public HttpResponseMessage GetPreviewMarkup([FromBody] JObject item, int parentId)
        {
            // Get parent to container node
            //TODO: Convert IContent if no published content?
            var parent = UmbracoContext.ContentCache.GetById(parentId);

            // Convert item
            var content = InnerContentHelper.ConvertInnerContentToPublishedContent(item, parent);

            // Construct preview model
            var model = new PreviewModel {
                Page = parent, Item = content
            };

            // Render view
            var markup = ViewHelper.RenderPartial(content.DocumentTypeAlias, model, new[]
            {
                "~/Views/Partials/Stack/{0}.cshtml",
                "~/Views/Partials/Stack/Default.cshtml",
            });

            // Return response
            var response = new HttpResponseMessage
            {
                Content = new StringContent(markup ?? "")
            };

            response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");

            return(response);
        }
Пример #2
0
        protected void ConvertInnerContentDbToString(JObject item)
        {
            if (item == null)
            {
                return;
            }

            var contentType = InnerContentHelper.GetContentTypeFromItem(item);

            if (contentType == null)
            {
                return;
            }

            var propValueKeys = item.Properties().Select(x => x.Name).ToArray();

            foreach (var propKey in propValueKeys)
            {
                var propType = contentType.CompositionPropertyTypes.FirstOrDefault(x => x.Alias == propKey);
                if (propType == null)
                {
                    if (IsSystemPropertyKey(propKey) == false)
                    {
                        // Property missing so just delete the value
                        item[propKey] = null;
                    }
                }
                else
                {
                    try
                    {
                        // Create a fake property using the property abd stored value
                        var prop = new Property(propType, item[propKey] == null ? null : item[propKey].ToString());

                        // Lookup the property editor
                        var propEditor = PropertyEditorResolver.Current.GetByAlias(propType.PropertyEditorAlias);

                        // Get the editor to do it's conversion, and store it back
                        item[propKey] = propEditor.ValueEditor.ConvertDbToString(prop, propType,
                                                                                 ApplicationContext.Current.Services.DataTypeService);
                    }
                    catch (InvalidOperationException)
                    {
                        // https://github.com/umco/umbraco-nested-content/issues/111
                        // Catch any invalid cast operations as likely means courier failed due to missing
                        // or trashed item so couldn't convert a guid back to an int

                        item[propKey] = null;
                    }
                }
            }

            // Process children
            var childrenProp = item.Properties().FirstOrDefault(x => x.Name == "children");

            if (childrenProp != null)
            {
                ConvertInnerContentDbToString(childrenProp.Value.Value <JArray>());
            }
        }
Пример #3
0
        protected bool TryEnsureContentTypeGuids(JArray items)
        {
            if (items == null)
            {
                return(false);
            }

            var ensured = false;

            foreach (JObject item in items)
            {
                var contentTypeGuid = item[InnerContentConstants.ContentTypeGuidPropertyKey];
                if (contentTypeGuid != null)
                {
                    continue;
                }

                var contentTypeAlias = item[InnerContentConstants.ContentTypeAliasPropertyKey];
                if (contentTypeAlias == null)
                {
                    continue;
                }

                InnerContentHelper.SetContentTypeGuid(item, contentTypeAlias.Value <string>(), ApplicationContext.Current.Services.ContentTypeService);
                ensured = true;
            }

            return(ensured);
        }
 protected IEnumerable <IPublishedContent> ConvertInnerContentDataToSource(
     JArray items,
     IPublishedContent parentNode = null,
     int level    = 0,
     bool preview = false)
 {
     return(InnerContentHelper.ConvertInnerContentToPublishedContent(items, parentNode, level, preview));
 }
 protected IPublishedContent ConvertInnerContentDataToSource(
     JObject item,
     IPublishedContent parentNode = null,
     int sortOrder = 0,
     int level     = 0,
     bool preview  = false)
 {
     return(InnerContentHelper.ConvertInnerContentToPublishedContent(item, parentNode, sortOrder, level, preview));
 }
Пример #6
0
        protected void ConvertInnerContentEditorToDb(JObject item)
        {
            if (item == null)
            {
                return;
            }

            var contentType = InnerContentHelper.GetContentTypeFromItem(item);

            if (contentType == null)
            {
                return;
            }

            var propValueKeys = item.Properties().Select(x => x.Name).ToArray();

            foreach (var propKey in propValueKeys)
            {
                var propType = contentType.CompositionPropertyTypes.FirstOrDefault(x => x.Alias == propKey);
                if (propType == null)
                {
                    if (IsSystemPropertyKey(propKey) == false)
                    {
                        // Property missing so just delete the value
                        item[propKey] = null;
                    }
                }
                else
                {
                    // Fetch the property types prevalue
                    var propPreValues = ApplicationContext.Current.Services.DataTypeService.GetPreValuesCollectionByDataTypeId(
                        propType.DataTypeDefinitionId);

                    // Lookup the property editor
                    var propEditor = PropertyEditorResolver.Current.GetByAlias(propType.PropertyEditorAlias);

                    // Create a fake content property data object
                    var contentPropData = new ContentPropertyData(
                        item[propKey], propPreValues,
                        new Dictionary <string, object>());

                    // Get the property editor to do it's conversion
                    var newValue = propEditor.ValueEditor.ConvertEditorToDb(contentPropData, item[propKey]);

                    // Store the value back
                    item[propKey] = (newValue == null) ? null : JToken.FromObject(newValue);
                }
            }

            // Process children
            var childrenProp = item.Properties().FirstOrDefault(x => x.Name == "children");

            if (childrenProp != null)
            {
                ConvertInnerContentEditorToDb(childrenProp.Value.Value <JArray>());
            }
        }
Пример #7
0
        public HttpResponseMessage GetPreviewMarkup([FromBody] JObject item, int pageId)
        {
            var page = default(IPublishedContent);

            // If the page is new, then the ID will be zero
            if (pageId > 0)
            {
                // TODO: Review. Previewing multiple blocks on the same page will make subsequent calls to the ContentService. Is it cacheable? [LK:2018-12-12]
                // Get page container node, otherwise it's unpublished then fake PublishedContent (by IContent object)
                page = UmbracoContext.ContentCache.GetById(pageId) ?? new UnpublishedContent(pageId, Services);

                // Ensure PublishedContentRequest exists, just in case there are any RTE Macros to render
                if (UmbracoContext.PublishedContentRequest == null)
                {
                    var pageUrl = page.UrlAbsolute();

                    // If the page is unpublished, then the URL will be empty or a hash '#'.
                    // Use the current request as a fallback, as we need to give the PublishedContentRequest a URI.
                    if (string.IsNullOrEmpty(pageUrl) || pageUrl.Equals("#"))
                    {
                        pageUrl = string.Concat(Request.RequestUri.GetLeftPart(UriPartial.Authority), "/#", pageId);
                    }

#pragma warning disable CS0618 // Type or member is obsolete
                    var pcr = new PublishedContentRequest(new Uri(pageUrl), UmbracoContext.RoutingContext);
#pragma warning restore CS0618 // Type or member is obsolete

                    UmbracoContext.PublishedContentRequest = pcr;
                    UmbracoContext.PublishedContentRequest.PublishedContent = page;
                    UmbracoContext.PublishedContentRequest.Prepare();
                }
            }

            // TODO: Review. The values in `item` are the "editor values", whereas for prevalue-based editors, the converter is expecting the "database value". [LK:2018-12-12]

            // Convert item
            var content = InnerContentHelper.ConvertInnerContentToPublishedContent(item, page);

            // Construct preview model
            var model = new PreviewModel {
                Page = page, Item = content
            };

            // Render view
            var markup = ViewHelper.RenderPartial(content.DocumentTypeAlias, model);

            // Return response
            var response = new HttpResponseMessage
            {
                Content = new StringContent(markup ?? string.Empty)
            };

            response.Content.Headers.ContentType = new MediaTypeHeaderValue(MediaTypeNames.Text.Html);

            return(response);
        }
        public SimpleNotificationModel CreateBlueprintFromContent([FromBody] JObject item, int userId = 0)
        {
            var blueprint = InnerContentHelper.ConvertInnerContentToBlueprint(item, userId);

            Services.ContentService.SaveBlueprint(blueprint, userId);

            return(new SimpleNotificationModel(new Notification(
                                                   Services.TextService.Localize("blueprints/createdBlueprintHeading"),
                                                   Services.TextService.Localize("blueprints/createdBlueprintMessage", new[] { blueprint.Name }),
                                                   global::Umbraco.Web.UI.SpeechBubbleIcon.Success)));
        }
Пример #9
0
        public HttpResponseMessage GetPreviewMarkup([FromBody] JObject item, int pageId)
        {
            var page = default(IPublishedContent);

            // If the page is new, then the ID will be zero
            if (pageId > 0)
            {
                // Get page container node
                page = UmbracoContext.ContentCache.GetById(pageId);
                if (page == null)
                {
                    // If unpublished, then fake PublishedContent (with IContent object)
                    page = new UnpublishedContent(pageId, Services);
                }
            }

            // Convert item
            var content = InnerContentHelper.ConvertInnerContentToPublishedContent(item, page);

            // Construct preview model
            var model = new PreviewModel {
                Page = page, Item = content
            };

            // Render view
            var markup = ViewHelper.RenderPartial(content.DocumentTypeAlias, model);

            // Return response
            var response = new HttpResponseMessage
            {
                Content = new StringContent(markup ?? string.Empty)
            };

            response.Content.Headers.ContentType = new MediaTypeHeaderValue(MediaTypeNames.Text.Html);

            return(response);
        }