/// <summary> /// Gets the form info for the given web part /// </summary> private FormInfo GetWebPartFormInfo() { // Load parent EnsureParentWebPartInfo(); if (wpi == null) { return(null); } string wpProperties = wpi.WebPartProperties; // Use parent web part if is defined if (parentWpi != null) { wpProperties = parentWpi.WebPartProperties; } // Get before FormInfo FormInfo beforeFI = null; if (BeforeFormDefinition == null) { beforeFI = PortalFormHelper.GetPositionFormInfo((WebPartTypeEnum)wpi.WebPartType, PropertiesPosition.Before); } else { beforeFI = new FormInfo(BeforeFormDefinition); } // Get after FormInfo FormInfo afterFI = null; if (AfterFormDefinition == null) { afterFI = PortalFormHelper.GetPositionFormInfo((WebPartTypeEnum)wpi.WebPartType, PropertiesPosition.After); } else { afterFI = new FormInfo(AfterFormDefinition); } // Add 'General' category at the beginning if no one is specified if (!string.IsNullOrEmpty(wpProperties) && (!wpProperties.StartsWithCSafe("<form><category", true))) { wpProperties = wpProperties.Insert(6, "<category name=\"" + GetString("general.general") + "\" />"); } // Get merged web part FormInfo FormInfo fi = PortalFormHelper.GetWebPartFormInfo(wpi.WebPartName, wpProperties, beforeFI, afterFI, true); return(fi); }
/// <summary> /// Returns form info with widget properties. /// </summary> /// <param name="wi">Widget</param> protected FormInfo GetWidgetProperties(WidgetInfo wi) { WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID); if (wpi != null) { string widgetProperties = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties); FormInfo zoneTypeDefinition = PortalFormHelper.GetPositionFormInfo(zoneType); FormInfo fi = PortalFormHelper.GetWidgetFormInfo(wi.WidgetName, Enum.GetName(typeof(WidgetZoneTypeEnum), zoneType), widgetProperties, zoneTypeDefinition, false); return(fi); } return(null); }
protected void Page_Load(object sender, EventArgs e) { StringSafeDictionary <object> decodedProperties = new StringSafeDictionary <object>(); foreach (DictionaryEntry param in mProperties) { // Decode special CK editor char String str = String.Empty; if (param.Value != null) { str = param.Value.ToString().Replace("%25", "%"); } decodedProperties[param.Key] = HttpUtility.UrlDecode(str); } mProperties = decodedProperties; string widgetName = ValidationHelper.GetString(mProperties["name"], String.Empty); // Widget name must be specified if (String.IsNullOrEmpty(widgetName)) { AddErrorWebPart("widgets.invalidname", null); return; } WidgetInfo wi = WidgetInfoProvider.GetWidgetInfo(widgetName); if (wi == null) { AddErrorWebPart("widget.failedtoload", null); return; } WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID); if (wpi == null) { return; } //no widgets can be used as inline if (!wi.WidgetForInline) { AddErrorWebPart("widgets.cantbeusedasinline", null); return; } try { // Merge widget and it's parent webpart properties string properties = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties); // Prepare form WidgetZoneTypeEnum zoneType = WidgetZoneTypeEnum.Editor; FormInfo zoneTypeDefinition = PortalFormHelper.GetPositionFormInfo(zoneType); FormInfo fi = PortalFormHelper.GetWidgetFormInfo(wi.WidgetName, Enum.GetName(typeof(WidgetZoneTypeEnum), zoneType), properties, zoneTypeDefinition, true); // Apply changed values DataRow dr = fi.GetDataRow(); fi.LoadDefaultValues(dr); fi.LoadDefaultValues(dr, wi.WidgetDefaultValues); // Incorporate inline parameters to datarow string publicFields = ";containertitle;container;"; if (wi.WidgetPublicFileds != null) { publicFields += ";" + wi.WidgetPublicFileds.ToLowerCSafe() + ";"; } // Load the widget control string url = null; // Set widget layout WebPartLayoutInfo wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wi.WidgetLayoutID); if (wpli != null) { // Load specific layout through virtual path url = wpli.GetVirtualFileRelativePath(WebPartLayoutInfo.EXTERNAL_COLUMN_CODE, wpli.WebPartLayoutVersionGUID); } else { // Load regularly url = WebPartInfoProvider.GetWebPartUrl(wpi, false); } CMSAbstractWebPart control = (CMSAbstractWebPart)Page.LoadUserControl(url); control.PartInstance = new WebPartInstance(); // Set all form values to webpart foreach (DataColumn column in dr.Table.Columns) { object value = dr[column]; string columnName = column.ColumnName.ToLowerCSafe(); //Resolve set values by user if (mProperties.Contains(columnName)) { FormFieldInfo ffi = fi.GetFormField(columnName); if ((ffi != null) && ffi.Visible && (!ffi.DisplayIn.Contains(FormInfo.DISPLAY_CONTEXT_DASHBOARD))) { value = mProperties[columnName]; } } // Resolve macros in defined in default values if (!String.IsNullOrEmpty(value as string)) { // Do not resolve macros for public fields if (publicFields.IndexOfCSafe(";" + columnName + ";") < 0) { // Check whether current column bool avoidInjection = control.SQLProperties.Contains(";" + columnName + ";"); // Resolve macros value = control.ContextResolver.ResolveMacros(value.ToString(), avoidInjection); } } control.PartInstance.SetValue(column.ColumnName, value); } control.PartInstance.IsWidget = true; // Load webpart content control.OnContentLoaded(); // Add webpart to controls collection Controls.Add(control); // Handle DisableViewstate setting control.EnableViewState = !control.DisableViewState; } catch (Exception ex) { AddErrorWebPart("widget.failedtoload", ex); } }
/// <summary> /// Init event handler. /// </summary> protected override void OnInit(EventArgs e) { base.OnInit(e); // Setup basic form on live site formCustom.AllowMacroEditing = false; formCustom.IsLiveSite = IsLiveSite; // Load settings if (!String.IsNullOrEmpty(Request.Form[hdnIsNewWebPart.UniqueID])) { IsNewWidget = ValidationHelper.GetBoolean(Request.Form[hdnIsNewWebPart.UniqueID], false); } if (!String.IsNullOrEmpty(Request.Form[hdnInstanceGUID.UniqueID])) { InstanceGUID = ValidationHelper.GetGuid(Request.Form[hdnInstanceGUID.UniqueID], Guid.Empty); } // Try to find the widget variant in the database and set its VariantID if (IsNewVariant) { Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable; if (properties != null) { // Get the variant code name from the WindowHelper string variantName = ValidationHelper.GetString(properties["codename"], string.Empty); // Check if the variant exists in the database int variantIdFromDB = 0; if (VariantMode == VariantModeEnum.MVT) { variantIdFromDB = ModuleCommands.OnlineMarketingGetMVTVariantId(PageTemplateId, variantName); } else if (VariantMode == VariantModeEnum.ContentPersonalization) { variantIdFromDB = ModuleCommands.OnlineMarketingGetContentPersonalizationVariantId(PageTemplateId, variantName); } // Set the variant id from the database if (variantIdFromDB > 0) { VariantID = variantIdFromDB; IsNewVariant = false; } } } EnsureDashboard(); if (!String.IsNullOrEmpty(WidgetId) && !IsInline) { // Get page info try { pi = CMSWebPartPropertiesPage.GetPageInfo(AliasPath, PageTemplateId, CultureCode); } catch (PageNotFoundException) { // Do not throw exception if page info not found (e.g. bad alias path) } if (pi == null) { lblInfo.Text = GetString("Widgets.Properties.aliasnotfound"); lblInfo.Visible = true; pnlFormArea.Visible = false; return; } // Get template instance templateInstance = CMSPortalManager.GetTemplateInstanceForEditing(pi); if (!IsNewWidget) { // Get the instance of widget widgetInstance = templateInstance.GetWebPart(InstanceGUID, WidgetId); if (widgetInstance == null) { lblInfo.Text = GetString("Widgets.Properties.WidgetNotFound"); lblInfo.Visible = true; pnlFormArea.Visible = false; return; } if ((VariantID > 0) && (widgetInstance != null) && (widgetInstance.PartInstanceVariants != null)) { // Check OnlineMarketing permissions. if (CheckPermissions("Read")) { widgetInstance = pi.DocumentTemplateInstance.GetWebPart(InstanceGUID, WidgetId); widgetInstance = widgetInstance.PartInstanceVariants.Find(v => v.VariantID.Equals(VariantID)); // Set the widget variant mode if (widgetInstance != null) { VariantMode = widgetInstance.VariantMode; } } else { // Not authorized for OnlineMarketing - Manage. RedirectToInformation(String.Format(GetString("general.permissionresource"), "Read", (VariantMode == VariantModeEnum.ContentPersonalization) ? "CMS.ContentPersonalization" : "CMS.MVTest")); } } // Get widget info by widget name(widget type) wi = WidgetInfoProvider.GetWidgetInfo(widgetInstance.WebPartType); } // Widget instance hasn't created yet else { wi = WidgetInfoProvider.GetWidgetInfo(ValidationHelper.GetInteger(WidgetId, 0)); } // Keep xml version if (widgetInstance != null) { xmlVersion = widgetInstance.XMLVersion; } CMSPage.EditedObject = wi; zoneType = ZoneType; // Get the zone to which it inserts WebPartZoneInstance zone = templateInstance.GetZone(ZoneId); if ((zoneType == WidgetZoneTypeEnum.None) && (zone != null)) { zoneType = zone.WidgetZoneType; } // Check security CurrentUserInfo currentUser = CMSContext.CurrentUser; switch (zoneType) { // Group zone => Only group widgets and group admin case WidgetZoneTypeEnum.Group: // Should always be, only group widget are allowed in group zone if (!wi.WidgetForGroup || (!currentUser.IsGroupAdministrator(pi.NodeGroupID) && ((CMSContext.ViewMode != ViewModeEnum.Design) || ((CMSContext.ViewMode == ViewModeEnum.Design) && (!currentUser.IsAuthorizedPerResource("CMS.Design", "Design")))))) { if (OnNotAllowed != null) { OnNotAllowed(this, null); } } break; // Widget must be allowed for editor zones case WidgetZoneTypeEnum.Editor: if (!wi.WidgetForEditor) { if (OnNotAllowed != null) { OnNotAllowed(this, null); } } break; // Widget must be allowed for user zones case WidgetZoneTypeEnum.User: if (!wi.WidgetForUser) { if (OnNotAllowed != null) { OnNotAllowed(this, null); } } break; // Widget must be allowed for dashboard zones case WidgetZoneTypeEnum.Dashboard: if (!wi.WidgetForDashboard) { if (OnNotAllowed != null) { OnNotAllowed(this, null); } } break; } // Check security if ((zoneType != WidgetZoneTypeEnum.Group) && !WidgetRoleInfoProvider.IsWidgetAllowed(wi, currentUser.UserID, currentUser.IsAuthenticated())) { if (OnNotAllowed != null) { OnNotAllowed(this, null); } } // Get form schemas wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID); FormInfo zoneTypeDefinition = PortalFormHelper.GetPositionFormInfo(zoneType); string widgetProperties = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties); FormInfo fi = PortalFormHelper.GetWidgetFormInfo(wi.WidgetName, Enum.GetName(typeof(WidgetZoneTypeEnum), zoneType), widgetProperties, zoneTypeDefinition, true); if (fi != null) { // Check if there are some editable properties var ffi = fi.GetFields(true, false).ToList <FormFieldInfo>(); if ((ffi == null) || (ffi.Count == 0)) { lblInfo.Visible = true; lblInfo.Text = GetString("widgets.emptyproperties"); } // Get datarows with required columns DataRow dr = PortalHelper.CombineWithDefaultValues(fi, wi); // Load default values for new widget if (IsNewWidget || (xmlVersion > 0)) { fi.LoadDefaultValues(dr, FormResolveTypeEnum.Visible); } if (IsNewWidget) { // Override default value and set title as widget display name DataHelper.SetDataRowValue(dr, "WidgetTitle", ResHelper.LocalizeString(wi.WidgetDisplayName)); } // Load values from existing widget LoadDataRowFromWidget(dr, fi); // Init HTML toolbar if exists InitHTMLToobar(fi); // Init the form InitForm(formCustom, dr, fi); // Set the context name formCustom.ControlContext.ContextName = CMS.SiteProvider.ControlContext.WIDGET_PROPERTIES; } } if (IsInline) { // Load text definition from session string definition = ValidationHelper.GetString(SessionHelper.GetValue("WidgetDefinition"), string.Empty); if (String.IsNullOrEmpty(definition)) { definition = Request.Form[hdnWidgetDefinition.UniqueID]; } else { hdnWidgetDefinition.Value = definition; } Hashtable parameters = null; if (IsNewWidget) { // New widget - load widget info by id if (!String.IsNullOrEmpty(WidgetId)) { wi = WidgetInfoProvider.GetWidgetInfo(ValidationHelper.GetInteger(WidgetId, 0)); } else { // Try to get widget from codename mName = QueryHelper.GetString("WidgetName", String.Empty); wi = WidgetInfoProvider.GetWidgetInfo(mName); } } else { if (definition == null) { DisplayError("widget.failedtoload"); return; } // Parse definition parameters = CMSDialogHelper.GetHashTableFromString(definition); // Trim control name if (parameters["name"] != null) { mName = parameters["name"].ToString(); } wi = WidgetInfoProvider.GetWidgetInfo(mName); } if (wi == null) { DisplayError("widget.failedtoload"); return; } // If widget cant be used as inline if (!wi.WidgetForInline) { DisplayError("widget.cantbeusedasinline"); return; } // Test permission for user CurrentUserInfo currentUser = CMSContext.CurrentUser; if (!WidgetRoleInfoProvider.IsWidgetAllowed(wi, currentUser.UserID, currentUser.IsAuthenticated())) { mIsValidWidget = false; OnNotAllowed(this, null); } // If user is editor, more properties are shown WidgetZoneTypeEnum zoneType = WidgetZoneTypeEnum.User; if (currentUser.IsEditor) { zoneType = WidgetZoneTypeEnum.Editor; } WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID); string widgetProperties = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties); FormInfo zoneTypeDefinition = PortalFormHelper.GetPositionFormInfo(zoneType); FormInfo fi = PortalFormHelper.GetWidgetFormInfo(wi.WidgetName, Enum.GetName(typeof(WidgetZoneTypeEnum), zoneType), widgetProperties, zoneTypeDefinition, true); if (fi != null) { // Check if there are some editable properties mFields = fi.GetFields(true, true); if ((mFields == null) || !mFields.Any()) { lblInfo.Visible = true; lblInfo.Text = GetString("widgets.emptyproperties"); } // Get datarows with required columns DataRow dr = PortalHelper.CombineWithDefaultValues(fi, wi); if (IsNewWidget) { // Load default values for new widget fi.LoadDefaultValues(dr, FormResolveTypeEnum.Visible); } else { foreach (string key in parameters.Keys) { object value = parameters[key]; // Test if given property exists if (dr.Table.Columns.Contains(key) && (value != null)) { try { dr[key] = DataHelper.ConvertValue(value, dr.Table.Columns[key].DataType); } catch { } } } } // Override default value and set title as widget display name DataHelper.SetDataRowValue(dr, "WidgetTitle", wi.WidgetDisplayName); // Init HTML toolbar if exists InitHTMLToobar(fi); // Init the form InitForm(formCustom, dr, fi); // Set the context name formCustom.ControlContext.ContextName = CMS.SiteProvider.ControlContext.WIDGET_PROPERTIES; } } }
/// <summary> /// Adds the inline widget without the properties dialog. /// </summary> /// <param name="widgetId">The widget id</param> private string AddInlineWidgetWithoutDialog(int widgetId) { string script = string.Empty; if (widgetId > 0) { // New widget - load widget info by id WidgetInfo wi = WidgetInfoProvider.GetWidgetInfo(widgetId); if ((wi != null) && wi.WidgetForInline) { // Test permission for user CurrentUserInfo currentUser = CMSContext.CurrentUser; if (!WidgetRoleInfoProvider.IsWidgetAllowed(widgetId, currentUser.UserID, currentUser.IsAuthenticated())) { return(string.Empty); } // If user is editor, more properties are shown WidgetZoneTypeEnum zoneType = WidgetZoneTypeEnum.User; if (currentUser.IsEditor) { zoneType = WidgetZoneTypeEnum.Editor; } WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID); // Get the properties xml according to the zone type FormInfo zoneTypeDefinition = PortalFormHelper.GetPositionFormInfo(zoneType); // Merge the parent web part properties definition with the widget properties definition string widgetProperties = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties); // Create the FormInfo for the current widget properties definition FormInfo fi = PortalFormHelper.GetWidgetFormInfo(wi.WidgetName, Enum.GetName(typeof(WidgetZoneTypeEnum), zoneType), widgetProperties, zoneTypeDefinition, true); DataRow dr = null; if (fi != null) { // Check if there are some editable properties List <FormFieldInfo> mFields = fi.GetFields(true, true); // Get data rows with required columns dr = PortalHelper.CombineWithDefaultValues(fi, wi); // Load default values for new widget fi.LoadDefaultValues(dr, FormResolveTypeEnum.Visible); // Override default value and set title as widget display name DataHelper.SetDataRowValue(dr, "WidgetTitle", wi.WidgetDisplayName); } // Save inline widget script script = PortalHelper.GetAddInlineWidgetScript(wi, dr, fi.GetFields(true, true)); script += " CloseDialog();"; if (!string.IsNullOrEmpty(script)) { // Add to recently used widgets collection CMSContext.CurrentUser.UserSettings.UpdateRecentlyUsedWidget(wi.WidgetName); } } } return(script); }