/// <summary> /// Parse the content item content to populate a DNN Hangout object /// </summary> /// <param name="contentItem"></param> /// <returns></returns> private HangoutInfo ParseContentItemForHangout(ContentItem contentItem) { var hangout = new HangoutInfo(); if (contentItem != null && !string.IsNullOrEmpty(contentItem.Content)) { hangout = contentItem.Content.FromJson<HangoutInfo>(); } return hangout; }
/// <summary> /// This method updates an existing content item /// </summary> /// <param name="tabId"></param> /// <param name="moduleId"></param> /// <param name="contentItemId"></param> /// <param name="bookmark"></param> /// <remarks>This method will only be present in DNN 6.2.3 and newer</remarks> public int UpdateContentItem(int tabId, int moduleId, int contentItemId, HangoutInfo hangout) { // get a reference to the original content item var objContent = Util.GetContentController().GetContentItem(contentItemId); // if the content item doesn't exist, send back to the calling method // NOTE: Probably should just throw an exception here if (objContent == null) return Null.NullInteger; // update the relevant properties objContent.Content = JsonExtensionsWeb.ToJsonString(hangout); // these are just for data posterity and probably don't need to be done objContent.ModuleID = moduleId; objContent.TabID = tabId; // data integrity check for legacy data (just in case stuff) if (!Regex.IsMatch(objContent.ContentKey, CONTENT_KEY_FORMAT_PATTERN, RegexOptions.IgnoreCase)) { objContent.ContentKey = string.Format(CONTENT_KEY_FORMAT, objContent.ContentItemId); } // execute the update on the database Util.GetContentController().UpdateContentItem(objContent); return contentItemId; }
/// <summary> /// This method creates new DNN Hangout entries in the content item data store /// </summary> /// <param name="tabId"></param> /// <param name="moduleId"></param> /// <param name="bookmark"></param> /// <returns></returns> public int CreateContentItem(int tabId, int moduleId, HangoutInfo hangout) { // create a new content item var objContent = new ContentItem { Content = JsonExtensionsWeb.ToJsonString(hangout), ContentTypeId = DNNHangoutContentTypeId, Indexed = false, ModuleID = moduleId, TabID = tabId }; // save the content item to the database objContent.ContentItemId = Util.GetContentController().AddContentItem(objContent); // update the objects with the new content item id retrieved in the line above hangout.ContentItemId = objContent.ContentItemId; // update the content item properties with proper content objContent.Content = JsonExtensionsWeb.ToJsonString(hangout); objContent.ContentKey = string.Format(CONTENT_KEY_FORMAT, hangout.ContentItemId); // update the content item again since we now have a contentItemId for the properties Util.GetContentController().UpdateContentItem(objContent); // return the content item id return objContent.ContentItemId; }
public string ReplaceTokens(string Template, HangoutInfo Hangout, PortalSettings Settings, int ModuleId, string LocalResourceFile) { var cachedTemplate = DataCache.GetCache(string.Format(TEMPLATE_CACHE_KEY_FORMAT, Hangout.ContentItemId)); // check for a cached template first if (cachedTemplate != null) { return cachedTemplate.ToString(); } /* * workaround for the JSON deserializer bug in DNN's NewtonSoft */ Hangout.StartDate = Hangout.StartDate.AddHours(-7); // begin replacing tokens Template = Regex.Replace(Template, TOKEN_TITLE, Hangout.Title); Template = Regex.Replace(Template, TOKEN_ADDRESS, Hangout.HangoutAddress); Template = Regex.Replace(Template, TOKEN_DESCRIPTION, HttpUtility.HtmlDecode(Hangout.Description)); Template = Regex.Replace(Template, TOKEN_DURATION, Hangout.Duration.ToString()); Template = Regex.Replace(Template, TOKEN_STARTDATE, Hangout.StartDate.ToString("MM/dd/yyyy hh:mm tt")); // todo: make this a setting if (Hangout.DurationUnits == DurationType.Minutes) { Template = Regex.Replace(Template, TOKEN_DURATIONUNITS, Localization.GetString("Minutes.Text", LocalResourceFile)); } else { if (Hangout.Duration > 1) { Template = Regex.Replace(Template, TOKEN_DURATIONUNITS, Localization.GetString("Hours.Text", LocalResourceFile)); } else { Template = Regex.Replace(Template, TOKEN_DURATIONUNITS, Localization.GetString("Hour.Text", LocalResourceFile)); } } var tr = new TokenReplace(); tr.AccessingUser = UserController.GetCurrentUserInfo(); tr.DebugMessages = Settings.UserMode != PortalSettings.Mode.View; tr.ModuleId = ModuleId; tr.PortalSettings = Settings; // replace DNN tokens var template = tr.ReplaceEnvironmentTokens(Template); // cache the template DataCache.SetCache(string.Format(TEMPLATE_CACHE_KEY_FORMAT, Hangout.ContentItemId), template, DateTime.Now.AddMinutes(10)); return template; }
private void SaveHangout() { var ctlHangout = new DNNHangoutController(); var sec = new PortalSecurity(); HangoutInfo hangout = null; // get an instance of the hangout (if necessary) if (Hangout == null) { hangout = new HangoutInfo(); } else { hangout = Hangout; } // populate the hangout with the user field values hangout.Description = sec.InputFilter(txtDescription.Text.Trim(), PortalSecurity.FilterFlag.NoScripting); hangout.Duration = int.Parse(sec.InputFilter(txtDuration.Text.Trim(), PortalSecurity.FilterFlag.NoMarkup), NumberStyles.Integer); hangout.HangoutAddress = sec.InputFilter(txtHangoutAddress.Text.Trim(), PortalSecurity.FilterFlag.NoScripting); hangout.StartDate = txtStartDate.SelectedDate != null ? txtStartDate.SelectedDate.Value : DateTime.Now; hangout.Title = sec.InputFilter(txtTitle.Text.Trim(), PortalSecurity.FilterFlag.NoMarkup); // determine the units to use if (ddlDurationUnits.SelectedIndex == 0) { hangout.DurationUnits = DurationType.Minutes; } else { hangout.DurationUnits = DurationType.Hours; } var contentItemId = Null.NullInteger; // update or create the hangout if (HangoutId > Null.NullInteger) { // update hangout contentItemId = ctlHangout.UpdateContentItem(TabId, ModuleId, hangout.ContentItemId, hangout); } else { // new hangout contentItemId = ctlHangout.CreateContentItem(TabId, ModuleId, hangout); } if (contentItemId > Null.NullInteger) { // update the module settings to set the default Google Hangout to show on the first page load var ctlModule = new ModuleController(); ctlModule.UpdateTabModuleSetting(TabModuleId, DNNHangoutController.SETTINGS_HANGOUT_ID,contentItemId.ToString()); ModuleController.SynchronizeModule(ModuleId); } }