Example #1
0
        /// <summary>
        /// Returns all content that is tagged with the specified tag value and optional tag group
        /// </summary>
        /// <param name="tag"></param>
        /// <param name="tagGroup"></param>
        /// <returns></returns>
        public IEnumerable <IPublishedContent> GetContentByTag(string tag, string tagGroup = null)
        {
            //TODO: http://issues.umbraco.org/issue/U4-6899
            if (_wrappedQuery != null)
            {
                return(_wrappedQuery.GetContentByTag(tag, tagGroup));
            }

            var ids = _tagService.GetTaggedContentByTag(tag, tagGroup)
                      .Select(x => x.EntityId);

            return(_typedContentQuery.TypedContent(ids)
                   .Where(x => x != null));
        }
        /// <summary>
        /// Gets a content item from the cache
        /// </summary>
        /// <param name="contentQuery"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static IPublishedContent TypedContent(this ITypedPublishedContentQuery contentQuery, Udi id)
        {
            var guidUdi = id as GuidUdi;

            if (guidUdi == null)
            {
                throw new InvalidOperationException("UDIs for content items must be " + typeof(GuidUdi));
            }
            return(contentQuery.TypedContent(guidUdi.Guid));
        }
        /// <summary>
        /// Returns the content id based on the configured IContentErrorPage section
        /// </summary>
        /// <param name="errorPage"></param>
        /// <param name="entityService"></param>
        /// <param name="publishedContentQuery"></param>
        /// <returns></returns>
        internal static int?GetContentIdFromErrorPageConfig(IContentErrorPage errorPage, IEntityService entityService, ITypedPublishedContentQuery publishedContentQuery)
        {
            if (errorPage.HasContentId)
            {
                return(errorPage.ContentId);
            }

            if (errorPage.HasContentKey)
            {
                //need to get the Id for the GUID
                //TODO: When we start storing GUIDs into the IPublishedContent, then we won't have to look this up
                // but until then we need to look it up in the db. For now we've implemented a cached service for
                // converting Int -> Guid and vice versa.
                var found = entityService.GetIdForKey(errorPage.ContentKey, UmbracoObjectTypes.Document);
                if (found)
                {
                    return(found.Result);
                }
                return(null);
            }

            if (errorPage.ContentXPath.IsNullOrWhiteSpace() == false)
            {
                try
                {
                    //we have an xpath statement to execute
                    var xpathResult = UmbracoXPathPathSyntaxParser.ParseXPathQuery(
                        xpathExpression: errorPage.ContentXPath,
                        nodeContextId: null,
                        getPath: nodeid =>
                    {
                        var ent = entityService.Get(nodeid);
                        return(ent.Path.Split(',').Reverse());
                    },
                        publishedContentExists: i => publishedContentQuery.TypedContent(i) != null);

                    //now we'll try to execute the expression
                    var nodeResult = publishedContentQuery.TypedContentSingleAtXPath(xpathResult);
                    if (nodeResult != null)
                    {
                        return(nodeResult.Id);
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.Error <NotFoundHandlerHelper>("Could not parse xpath expression: " + errorPage.ContentXPath, ex);
                    return(null);
                }
            }
            return(null);
        }
Example #4
0
        public PageInformation GetpageInformation(int id)
        {
            var pageInformation = new PageInformation();

            var content = _typedPublishedContentQuery.TypedContent(id);
            var html    = _templateHelper.GetNodeHtml(content);

            var htmlParser = new HtmlDocument();

            htmlParser.LoadHtml(HttpUtility.HtmlDecode(html));

            var headTag = htmlParser.DocumentNode.GetElements("head");

            if (headTag.Any())
            {
                var titleTags = headTag.First().GetElements("title");

                if (titleTags.Any())
                {
                    pageInformation.Title = titleTags.First().InnerText;
                }
            }

            var metaTags = htmlParser.DocumentNode.GetElements("meta");

            var attributeValues = from metaTag in metaTags
                                  let attribute = metaTag.GetAttribute("name")
                                                  where attribute != null
                                                  where attribute.Value == "description"
                                                  select metaTag.GetAttribute("content");

            if (attributeValues.Any())
            {
                pageInformation.Description = attributeValues.First().Value;
            }
            pageInformation.Url = content.UrlWithDomain();

            return(pageInformation);
        }
Example #5
0
        public IHttpActionResult AnalyzeNode(int id, string focusKeyword = null)
        {
            if (id < 1)
            {
                return(BadRequest());
            }

            try
            {
                var node     = _typedPublishedContentQuery.TypedContent(id);
                var analysis = _analyzeService.CreateAnalysis(node, focusKeyword);
                return(Ok(analysis));
            }
            catch (MissingFieldException ex)
            {
                return(InternalServerError(ex));
            }
            catch (Exception ex)
            {
                LogHelper.Error(typeof(AnalysisApiController), "RankOne AnalyzeNode Exception", ex);
                return(InternalServerError(ex));
            }
        }
Example #6
0
 public IPublishedContent GetTypedContentById(int id)
 {
     return(_umbracoContentQuery.TypedContent(id));
 }
 public IPublishedContent TypedContent(int id)
 {
     return(_typedContentQuery == null
         ? TypedDocumentById(id, _contentCache)
         : _typedContentQuery.TypedContent(id));
 }