Exemplo n.º 1
0
        void ContentService_Saving(IContentService sender, SaveEventArgs <IContent> args)
        {
            try
            {
                foreach (var entity in args.SavedEntities)
                {
                    if (entity.ContentType.Alias != "standardLandingPage")
                    {
                        continue;
                    }

                    var descriptionsProperty = entity.Properties["descriptions"];
                    if (descriptionsProperty == null)
                    {
                        continue;
                    }

                    string descriptionsValue = null;
                    if (descriptionsProperty.Value != null && !String.IsNullOrWhiteSpace(descriptionsProperty.Value.ToString()))
                    {
                        descriptionsValue = umbraco.library.GetPreValueAsString(Int32.Parse(descriptionsProperty.Value.ToString(), CultureInfo.InvariantCulture));
                    }

                    var useLinks = Views.StandardLandingPage.DisplayAsListsOfLinks(descriptionsValue, entity.Level);
                    for (var i = 1; i <= 15; i++)
                    {
                        var propertyAlias = "defDesc" + i.ToString("00", CultureInfo.InvariantCulture) + "_Content";
                        var html          = entity.GetValue <string>(propertyAlias);

                        if (html != null)
                        {
                            if (useLinks)
                            {
                                // Strip text outside links, and put links into a list
                                html = CmsUtilities.ShouldBeUnorderedList(html);
                            }
                            else
                            {
                                // Otherwise just strip any HTML from the placeholder, which will be there if pasted from Word - it should be a text description
                                html = new HtmlTagSanitiser().StripTags(html);
                            }

                            entity.SetValue(propertyAlias, html);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                e.ToExceptionless().Submit();
            }
        }