private void ParseCommentsView() { // if a setting isn't in place, let the end-user know if (this.AttachedModule > 0 && string.IsNullOrEmpty(DisqusApplicationName) == false && string.IsNullOrEmpty(DisqusApiSecret) == false) { // add the view this.phScript.Controls.Add(new LiteralControl(this.GetDisqusCommentsScript())); FeatureController ctlModule = new FeatureController(); DisqusInfo oComment = ctlModule.GetDisqusByModule(TabModuleId); divComments.Visible = ctlModule.IsSearchEngine(Request.UserAgent) && (oComment != null); if (divComments.Visible == true) { // generate & inject the HTML markup divComments.InnerHtml = GetCommentsForSearchEngines(oComment); } } else { // tell the user why we cannot add the view if (DisqusView == "comments" && this.AttachedModule < 1) { UI.Skins.Skin.AddModuleMessage(this, this.GetLocalizedString("NoModuleAttached.Text"), ModuleMessage.ModuleMessageType.YellowWarning); } if (DisqusView == "comments" && string.IsNullOrEmpty(DisqusApplicationName)) { UI.Skins.Skin.AddModuleMessage(this, this.GetLocalizedString("NoApplicationName.Text"), ModuleMessage.ModuleMessageType.YellowWarning); } if (DisqusView == "comments" && string.IsNullOrEmpty(DisqusApiSecret)) { UI.Skins.Skin.AddModuleMessage(this, this.GetLocalizedString("NoApiSecret.Text"), ModuleMessage.ModuleMessageType.YellowWarning); } } AttachModuleScript(); }
private void SaveResponse(FeatureController ctlModule, int PortalId, DisqusInfo oHeader, DisqusResponseInfo oResponse, int ItemId) { // assign the response to the header record oHeader.Response[0] = oResponse; // get a identity reference ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(MESSAGE_IDENTIFIER, oHeader.Response[0].Thread.Identifiers[0])); DisqusIdentifierInfo oIdentity = ctlModule.GetIdentifier(oHeader.Response[0].Thread.Identifiers[0]); try { // save the response object ctlModule.AddDisqus(PortalId, oIdentity.TabId, oIdentity.TabModuleId, oIdentity.RawUrl, SerializeToXML(oHeader), oHeader.Response[0].CreatedAt.ToString()); } catch (Exception exSave) { ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(ERROR_MESSAGE_1, ItemId)); ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(ERROR_MESSAGE_2, PortalId, oIdentity.TabId, oIdentity.TabModuleId, oIdentity.RawUrl, oHeader.Response[0].CreatedAt.ToString())); ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(ERROR_MESSAGE_3, exSave.Message, exSave.StackTrace)); } }
private string GetDisqusCommentsScript() { var sb = new StringBuilder(50); FeatureController ctlModule = new FeatureController(); AppendToStringBuilder(ref sb, "<div id=\"disqus_thread\"></div> "); AppendToStringBuilder(ref sb, "<script type=\"text/javascript\" language=\"javascript\"> "); // generate SSO stub for Disqus if (DisqusSsoEnabled && !string.IsNullOrEmpty(DisqusSsoApiKey)) { //AppendToStringBuilder(ref sb, "<script type=\"text/javascript\" language=\"javascript\"> "); AppendToStringBuilder(ref sb, "var disqus_config = function() { "); OAuthHelper auth = new OAuthHelper(); string strMessage = GetSsoMessage(); string strHmac = GetSsoHmac(strMessage, auth.GenerateTimeStamp()); string strPayload = string.Format("this.page.remote_auth_s3 = '{0} {1} {2}'; ", strMessage, strHmac, auth.GenerateTimeStamp()); AppendToStringBuilder(ref sb, strPayload); string strApiKey = string.Format("this.page.api_key = '{0}'; ", DisqusSsoApiKey); AppendToStringBuilder(ref sb, strApiKey); AppendToStringBuilder(ref sb, "}; "); //AppendToStringBuilder(ref sb, "</script> "); } //sb.Append("/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */"); if (DisqusDeveloperMode == true) { AppendToStringBuilder(ref sb, "var disqus_developer = 1; "); } else { AppendToStringBuilder(ref sb, "var disqus_developer = 0; "); } string strShortName = string.Format("var disqus_shortname = '{0}'; ", DisqusApplicationName); AppendToStringBuilder(ref sb, strShortName); //sb.Append("// The following are highly recommended additional parameters. Remove the slashes in front to use."); // need to parse for isolated views in DNN and add them to this identifier string strIdentifier = string.Format("var disqus_identifier = '{0}'; ", ctlModule.CreateUniqueIdentifier(TabId, TabModuleId, PortalSettings.GUID, Request.RawUrl)); AppendToStringBuilder(ref sb, strIdentifier); AppendToStringBuilder(ref sb, "var disqus_url = document.URL; "); //sb.Append("/* * * DON'T EDIT BELOW THIS LINE * * */"); AppendToStringBuilder(ref sb, "(function() { "); AppendToStringBuilder(ref sb, "var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; "); AppendToStringBuilder(ref sb, "dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js'; "); AppendToStringBuilder(ref sb, "(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); "); AppendToStringBuilder(ref sb, "})();"); AppendToStringBuilder(ref sb, "</script>"); AppendToStringBuilder(ref sb, "<noscript>Please enable JavaScript to view the <a href=\"http://disqus.com/?ref_noscript\">comments powered by Disqus.</a></noscript>"); AppendToStringBuilder(ref sb, "<!--<a href=\"http://disqus.com\" class=\"dsq-brlink\">blog comments powered by <span class=\"logo-disqus\">Disqus</span></a>-->"); return sb.ToString(); }
private void ImportCommentsFromDisqus() { PortalController ctlPortal = new PortalController(); ArrayList lstPortal = ctlPortal.GetPortals(); // cycle through each portal foreach (PortalInfo oPortal in lstPortal) { ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(MESSAGE_PROCESSING, oPortal.PortalID, oPortal.PortalName)); try { // if the portal has the site settings, import its comments string DisqusApplicationName = PortalController.GetPortalSetting(APPLICATION_NAME, oPortal.PortalID, string.Empty); if (string.IsNullOrEmpty(DisqusApplicationName) == false) { var ctlModule = new FeatureController(); string DisqusApiSecret = PortalController.GetPortalSetting(API_SECRET, oPortal.PortalID, string.Empty); string strResponse = ctlModule.GetContent( string.Format(ctlModule.GenericDisqusUrl(DisqusApplicationName, DisqusApiSecret), FeatureController.DISQUS_POST_LIST)); DisqusInfo oPosts = JsonConvert.DeserializeObject<DisqusInfo>(strResponse); ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(MESSAGE_CALLED, string.Format(ctlModule.GenericDisqusUrl(DisqusApplicationName, DisqusApiSecret), FeatureController.DISQUS_POST_LIST))); ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(MESSAGE_DISQUS_COMMENTS, oPosts.Response.Length)); /* * TODO: Finish the scheduler item * 1. Delete all posts from the DB for the Portal * 1. Save all responses to memory * 2. Slice up 1 per record * a. Be mindful of TabId, TabModuleId, PortalId * b. PortalId will require parsing to figure out * 3. Save to DB * 4. Determine if subsequent requests need to be made * a. Use the cursor to plan subsequent requests * b. Request repeatedly until the * I. API refuses the request * II. Cursor reveals no further records */ // delete all saved Disqus records for the site ScheduleHistoryItem.AddLogNote(Environment.NewLine + MESSAGE_DELETE_COMMENTS); ctlModule.DeleteDisqusbyPortal(oPortal.PortalID); ArrayList lstResponse = new ArrayList(); foreach (DisqusResponseInfo oResponse in oPosts.Response) { lstResponse.Add(oResponse); } ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(MESSAGE_LSTRESPONSE_COMMENTS, lstResponse.Count)); // build a header object DisqusInfo oHeader = oPosts; oHeader.Response = new DisqusResponseInfo[1]; ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(MESSAGE_OPOST_COMMENTS, oPosts.Response.Length)); ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(MESSAGE_OHEADER_COMMENTS, oHeader.Response.Length)); int i = 0; // iterate through all responses (comments) foreach (DisqusResponseInfo oResponse in lstResponse) { ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(MESSAGE_SAVING_COMMENT, i)); SaveResponse(ctlModule, oPortal.PortalID, oHeader, oResponse, i); ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(MESSAGE_COMMENT_SAVED, i)); i++; } ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(MESSAGE_COMMENT_SUMMARY, oPortal.PortalName, i)); } } catch(Exception ex) { Exceptions.LogException(ex); ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(MESSAGE_UNEXPECTED_ERROR, ex.Message, ex.StackTrace)); continue; } } }