protected override void ApplyVariation(CustomizeRenderingArgs args, ComponentTestContext context) { // Begin copied from sitecore Assert.ArgumentNotNull(args, "args"); Assert.ArgumentNotNull(context, "context"); ComponentTestRunner componentTestRunner = new ComponentTestRunner(); try { componentTestRunner.Run(context); } catch (Exception exception1) { Exception exception = exception1; string str = (ItemUtil.IsNull(context.Component.RenderingID) ? string.Empty : context.Component.RenderingID.ToString()); string str1 = (args.PageContext.Item != null ? args.PageContext.Item.ID.ToString() : string.Empty); Log.Warn("Failed to execute MV testing on component with id \"{0}\". Item ID:\"{1}\"".FormatWith(new object[] { str, str1 }), exception, this); } RenderingReference renderingReference = context.Components.FirstOrDefault <RenderingReference>((RenderingReference c) => c.UniqueId == context.Component.UniqueId); if (renderingReference == null) { args.Renderer = new EmptyRenderer(); return; } this.ApplyChanges(args.Rendering, renderingReference); // End copied from sitecore // Apply Parameters Too TransferRenderingParameters(args.Rendering, renderingReference); }
/// <summary> /// Checks if the user has write permissions for the selected language. /// </summary> /// <param name="language">The language to check permissons on.</param> /// <returns>True if the user has write permissons for the language.</returns> private bool CanWriteLanguage(Language language) { if (language == null) { return(false); } bool renderLanguage = true; if (Settings.CheckSecurityOnLanguages) { ID languageItemId = LanguageManager.GetLanguageItemId(language, _database); if (!ItemUtil.IsNull(languageItemId)) { Item languageItem = _database.GetItem(languageItemId); if (languageItem == null) { renderLanguage = false; } bool canWriteLanguage = AuthorizationManager.IsAllowed(languageItem, AccessRight.LanguageWrite, Context.User); if (!canWriteLanguage) { renderLanguage = false; } } else { renderLanguage = false; } } return(renderLanguage); }
private static string GetFieldValue(Item item, string fieldName) { Assert.ArgumentNotNull(item, "item"); Assert.ArgumentNotNull(fieldName, "fieldName"); var id = TemplateManager.GetFieldId(fieldName, item.TemplateID, item.Database); if (ItemUtil.IsNull(id)) { return(string.Empty); } return(item.InnerData.Fields[id] ?? string.Empty); }
protected override void OnLoad(EventArgs e) { Assert.ArgumentNotNull(e, "e"); base.OnLoad(e); if (!Context.ClientPage.IsEvent) { Item currentItem = GetCurrentItem(); if (currentItem != null) { foreach (Language language in currentItem.Languages) { ID languageItemId = LanguageManager.GetLanguageItemId(language, currentItem.Database); if (!ItemUtil.IsNull(languageItemId)) { Item languageItem = currentItem.Database.GetItem(languageItemId); if (languageItem == null || !languageItem.Access.CanRead() || languageItem.Appearance.Hidden && !UserOptions.View.ShowHiddenItems) { continue; } } Item item = currentItem.Database.GetItem(currentItem.ID, language); if (item != null) { int length = item.Versions.GetVersionNumbers(false).Length; if (length == 0) { continue; } XmlControl control = ControlFactory.GetControl("Gallery.Languages.Option") as XmlControl; if (control != null) { control["Icon"] = LanguageService.GetIcon(language, currentItem.Database); control["Header"] = Language.GetDisplayName(language.CultureInfo); control["Description"] = (length == 1) ? Translate.Text("1 version.") : Translate.Text("{0} versions.", length); control["Click"] = string.Format("item:addversionrecursive(id={0},sourceLang={1},targetLang={2})", currentItem.ID, language, currentItem.Language); control["ClassName"] = language.Name.Equals(WebUtil.GetQueryString("la"), StringComparison.OrdinalIgnoreCase) ? "scMenuPanelItemSelected" : "scMenuPanelItem"; Context.ClientPage.AddControl(Languages, control); } } } Context.ClientPage.AddControl(Options, new MenuLine()); } } }
/// <summary> /// Builds the languages. /// /// </summary> private void BuildLanguages() { this.Languages.Controls.Clear(); HtmlGenericControl checkboxControl = null; var profileLanguages = new ListString(Registry.GetString("/Current_User/Publish/Languages")); var languages = (from l in LanguageManager.GetLanguages(Context.ContentDatabase) orderby l.CultureInfo.DisplayName select l).ToList <Language>(); foreach (Language language in languages) { if (Settings.CheckSecurityOnLanguages) { ID languageItemId = LanguageManager.GetLanguageItemId(language, Context.ContentDatabase); if (!ItemUtil.IsNull(languageItemId)) { Item languageItem = Context.ContentDatabase.GetItem(languageItemId); if (languageItem == null || !CanPublishLanguage(languageItem)) { continue; } } else { continue; } } string uniqueId = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("la_"); checkboxControl = new HtmlGenericControl("input"); this.Languages.Controls.Add(checkboxControl); checkboxControl.Attributes["type"] = "checkbox"; checkboxControl.ID = uniqueId; checkboxControl.Attributes["value"] = language.Name; if (profileLanguages.IndexOf(language.ToString()) >= 0) { checkboxControl.Attributes["checked"] = "checked"; } var labelControl = new HtmlGenericControl("label"); this.Languages.Controls.Add(labelControl); labelControl.Attributes["for"] = uniqueId; labelControl.InnerText = language.CultureInfo.DisplayName; this.Languages.Controls.Add(new LiteralControl("<br>")); } if (languages.Count != 1 || checkboxControl == null) { return; } this.LanguagesPanel.Disabled = true; checkboxControl.Attributes["checked"] = "checked"; checkboxControl.Attributes["disabled"] = "disabled"; }
private string WriteValidators([NotNull] Item targetItem) { Debug.ArgumentNotNull(targetItem, nameof(targetItem)); var writer = new StringWriter(); var output = new XmlTextWriter(writer); output.WriteStartElement("validators"); var validatorCollection = ValidatorManager.BuildValidators(ValidatorsMode.ValidatorBar, targetItem); var options = new ValidatorOptions(true); ValidatorManager.Validate(validatorCollection, options); foreach (BaseValidator validator in validatorCollection) { if (validator.Result == ValidatorResult.Valid || validator.Result == ValidatorResult.Unknown) { continue; } var fieldId = string.Empty; var validatorFieldId = validator.FieldID; if (!ItemUtil.IsNull(validatorFieldId)) { fieldId = validatorFieldId.ToString(); } output.WriteStartElement("validator"); output.WriteAttributeString("fieldid", fieldId); output.WriteAttributeString("validatorid", validator.ValidatorID.ToString()); output.WriteAttributeString("result", ((int)validator.Result).ToString()); output.WriteValue(validator.Text); output.WriteEndElement(); } output.WriteEndElement(); return(writer.ToString()); }
/// <summary> /// Inserts a rendering. /// </summary> /// <param name="reference">The reference.</param> protected virtual void InsertRendering(RenderingReference reference) { Assert.ArgumentNotNull((object)reference, "reference"); Control control = reference.GetControl(); if (control == null) { RenderingItem renderingItem = reference.RenderingItem; Tracer.Error((object)("Could not instantiate control for the rendering '" + (renderingItem != null ? renderingItem.Name : "[unknown]") + "'")); } else { if (!ItemUtil.IsNull(reference.RenderingID)) { WebControl webControl = control as WebControl; if (webControl != null && string.IsNullOrEmpty(webControl.RenderingID)) { webControl.RenderingID = StringUtil.GetString((object)reference.RenderingID); } } this.InsertControl(control); } }
private bool Validate([NotNull] XmlTextWriter output, [NotNull] Item item) { Debug.ArgumentNotNull(output, nameof(output)); Debug.ArgumentNotNull(item, nameof(item)); var result = false; var validatorCollection = ValidatorManager.BuildValidators(ValidatorsMode.ValidatorBar, item); var options = new ValidatorOptions(true); ValidatorManager.Validate(validatorCollection, options); foreach (BaseValidator validator in validatorCollection) { if (validator.Result == ValidatorResult.Valid || validator.Result == ValidatorResult.Unknown) { continue; } var fieldId = string.Empty; var validatorFieldId = validator.FieldID; if (!ItemUtil.IsNull(validatorFieldId)) { fieldId = validatorFieldId.ToString(); } var validatorIcon = "Applications/16x16/preferences.png"; var category = "Validation"; var categoryIcon = "Applications/16x16/preferences.png"; var validatorItem = item.Database.GetItem(validator.ValidatorID); if (validatorItem != null) { validatorIcon = validatorItem.Appearance.Icon; category = validatorItem.Parent.Name; } output.WriteStartElement("issue"); output.WriteAttributeString("validatorid", validator.ValidatorID.ToString()); output.WriteAttributeString("validatorname", validator.Name); output.WriteAttributeString("validatoricon", Images.GetThemedImageSource(validatorIcon, ImageDimension.id16x16)); output.WriteAttributeString("itemid", item.ID.ToString()); output.WriteAttributeString("itemname", item.Name); output.WriteAttributeString("itemicon", Images.GetThemedImageSource(item.Appearance.Icon, ImageDimension.id16x16)); output.WriteAttributeString("categoryname", category); output.WriteAttributeString("categoryicon", Images.GetThemedImageSource(categoryIcon, ImageDimension.id16x16)); output.WriteAttributeString("path", item.Paths.Path); output.WriteAttributeString("fieldid", fieldId); output.WriteAttributeString("fieldname", validator.GetFieldDisplayName()); output.WriteAttributeString("icon", Images.GetThemedImageSource(validator.GetIcon(), ImageDimension.id16x16)); output.WriteAttributeString("result", ((int)validator.Result).ToString()); output.WriteValue(validator.Text); output.WriteEndElement(); result = true; } return(result); }