uBlogsy(webforms)PostService在登录页面上没有显示帖子

时间:2014-05-16 17:08:06

标签: umbraco umbraco6

我在Umbraco 6.1.5上使用uBlogsy WebForms 3.0.2 ...

目标网页上的帖子没有显示。

函数PostService.Instance.GetPosts返回0个帖子,即使帖子位于正确的位置。

当我尝试替换它时,我仍然会得到0个帖子:

var posts = PostService.Instance
                       .GetPosts(
                           IPublishedContentHelper.GetNode((int)Model.Id)
                       ).ToIPublishedContent(true);
int postCount = posts.Count();

有谁知道为什么邮政服务不起作用?或者,发生了什么?

1 个答案:

答案 0 :(得分:0)

我和Ublogsy有过同样的问题。所以我决定编写自己的代码如下:

(有点长)

// get tag, label, or author from query string
    var tag = Request.QueryString["tag"] ?? "";
    var label = Request.QueryString["label"] ?? "";
    var author = Request.QueryString["author"] ?? "";
    var searchTerm = Request.QueryString["search"] ?? "";
    var commenter = Request.QueryString["commenter"] ?? "";
    int page = int.TryParse(Request.QueryString["page"], out page) ? page : 1;
    var year = Request.QueryString["year"] ?? "";
    var month = Request.QueryString["month"] ?? "";
    var day = Request.QueryString["day"] ?? "";
    int postCount;

IEnumerable<IPublishedContent> posts = new BlockingCollection<IPublishedContent>();

var filterResults = this.FilterAgainstPosts(this.Model.Content, tag, label, author, searchTerm, commenter, year, month);
    if (filterResults != null)
    {
        posts = Enumerable.Take(filterResults.Skip((page - 1) * itemsPerPage), itemsPerPage);
    }

@RenderForLanding(posts)

我的FilterAgainstPosts方法如下:

@functions
{
private IEnumerable<IPublishedContent> FilterAgainstPosts(IPublishedContent landing, string tag, string label, string author, string searchTerm, string commenter, string year, string month)
    {
        IEnumerable<IPublishedContent> filteredPosts = landing.DescendantsOrSelf("uBlogsyPost").Where(x => x.GetProperty("umbracoNaviHide").Value.ToString() != "1");

        if (!String.IsNullOrEmpty(searchTerm))
        {
            filteredPosts = filteredPosts.ForEach(i => this.FilterAgainstTerm(i, searchTerm));
        }

        if (!String.IsNullOrEmpty(tag))
        {
            filteredPosts = filteredPosts.ForEach(i => this.FilterUponTag(i, i.GetProperty("uBlogsyPostTags").Value.ToString(), tag));
        }

        if (!String.IsNullOrEmpty(label))
        {
            filteredPosts = filteredPosts.ForEach(i => this.FilterUponLabel(i, i.GetProperty("uBlogsyPostLabels").Value.ToString(), label));
        }

        if (!String.IsNullOrEmpty(author))
        {
            filteredPosts = filteredPosts.ForEach(i => this.FilterUponAuthor(i, i.GetProperty("uBlogsyPostAuthor").Value.ToString(), author));
        }

        //
        //TODO: Coomenter search needs to added
        //

        if (!string.IsNullOrEmpty(year))
        {
            filteredPosts = filteredPosts.ForEach(i => this.FilterUponYear(i, i.GetProperty("uBlogsyPostDate").Value.ToString(), year));
        }

        if (!string.IsNullOrEmpty(month))
        {
            filteredPosts = filteredPosts.ForEach(i => this.FilterUponMonth(i, i.GetProperty("uBlogsyPostDate").Value.ToString(), month));
        }

        return filteredPosts.WhereNotNull();
    }

private IPublishedContent FilterUponMonth(IPublishedContent currentNode, string postDate, string month)
    {
        DateTime postedDate;
        if (DateTime.TryParse(postDate, out postedDate) && postedDate.Month.ToString() == month) return currentNode;

        return null;
    }

private IPublishedContent FilterUponYear(IPublishedContent currentNode, string postDate, string year)
    {
        DateTime postedDate;
        if (DateTime.TryParse(postDate, out postedDate) && postedDate.Year.ToString() == year) return currentNode;

        return null;
    }

private IPublishedContent FilterUponAuthor(IPublishedContent currentNode, string authorId, string author)
    {
        if (String.IsNullOrEmpty(authorId)) return null;
        //Loads relevant node
        int authorNodeId = -1;
        if (!Int32.TryParse(authorId, out authorNodeId)) return null;
        Node authorNode = new Node(authorNodeId);

        //Trims the author name and search for given name
        if (authorNode.GetProperty("uBlogsyAuthorName") != null && authorNode.GetProperty("uBlogsyAuthorName").Value.ToUpper().Trim().Contains(author.ToUpper())) return currentNode;

        return null;
    }


private Boolean FilterUponAuthor(string authorId, string author)
    {
        if (String.IsNullOrEmpty(authorId)) return false;

        int authorNodeId = -1;
        if (!Int32.TryParse(authorId, out authorNodeId)) return false;
        Node authorNode = new Node(authorNodeId);

        if (authorNode.GetProperty("uBlogsyAuthorName") != null && authorNode.GetProperty("uBlogsyAuthorName").Value.ToUpper().Trim().Contains(author.ToUpper())) return true;

        return false;
    }

private Boolean FilterUponCategories(string categoryIds, string category)
    {
        if (String.IsNullOrEmpty(categoryIds)) return false;

        int categoryNodeID = -1;

        foreach (string catID in categoryIds.Split(','))
        {
            if (!Int32.TryParse(catID, out categoryNodeID)) continue;
            Node categoryNode = new Node(categoryNodeID);

            if (categoryNode.GetProperty("uBlogsyLabelName") != null && categoryNode.GetProperty("uBlogsyLabelName").Value.ToUpper().Trim().Contains(category.ToUpper())) return true;
        }
        return false;
    }

private Boolean FilterUponTags(string tagIds, string tag)
    {
        if (String.IsNullOrEmpty(tagIds)) return false;

        int tagNodeID = -1;

        foreach (string tagID in tagIds.Split(','))
        {
            if (!Int32.TryParse(tagID, out tagNodeID)) continue;
            Node tagNode = new Node(tagNodeID);

            if (tagNode.GetProperty("uTagsyTagName") != null && tagNode.GetProperty("uTagsyTagName").Value.ToUpper().Trim().Contains(tag.ToUpper())) return true;
        }
        return false;
    }

private IPublishedContent FilterUponLabel(IPublishedContent currentNode, string nodeIDs, string label)
    {
        if (String.IsNullOrEmpty(nodeIDs)) return null;


        foreach (string nodeId in nodeIDs.Split(','))
        {
            int labelNodeId = -1;
            if (!Int32.TryParse(nodeId, out labelNodeId))
                continue;
            //Loads relevant node
            Node labelNode = new Node(labelNodeId);
            if (labelNode.GetProperty("uBlogsyLabelName") != null && labelNode.GetProperty("uBlogsyLabelName").Value.ToUpper().Trim().Contains(label.ToUpper())) return currentNode;
        }

        return null;
    }

private IPublishedContent FilterAgainstTerm(IPublishedContent currentNode, string searchTerm)
    {
        if (String.IsNullOrEmpty(searchTerm)) return currentNode;

        if (currentNode.GetProperty("uBlogsyContentTitle").Value.ToString().ToUpper().Contains(searchTerm.ToUpper()) || 
            currentNode.GetProperty("uBlogsyContentSummary").Value.ToString().ToUpper().Contains(searchTerm.ToUpper()) || 
            currentNode.GetProperty("uBlogsyContentBody").Value.ToString().ToUpper().Contains(searchTerm.ToUpper()) || 
            currentNode.GetProperty("uBlogsySeoKeywords").Value.ToString().ToUpper().Contains(searchTerm.ToUpper()) || 
            currentNode.GetProperty("uBlogsySeoDescription").Value.ToString().ToUpper().Contains(searchTerm.ToUpper()) || 
            currentNode.GetProperty("uBlogsyNavigationTitle").Value.ToString().ToUpper().Contains(searchTerm.ToUpper()) ||
            FilterUponAuthor(currentNode.GetProperty("uBlogsyPostAuthor").Value.ToString(), searchTerm.ToUpper()) ||
            FilterUponCategories(currentNode.GetProperty("uBlogsyPostLabels").Value.ToString(), searchTerm.ToUpper()) ||
            FilterUponTags(currentNode.GetProperty("uBlogsyPostTags").Value.ToString(), searchTerm.ToUpper())
            ) 
                return currentNode;
        return null;
    }

private IPublishedContent FilterUponTag(IPublishedContent currentNode, string nodeIDs, string tag)
    {
        if (String.IsNullOrEmpty(nodeIDs)) return null;

        foreach (string nodeId in nodeIDs.Split(','))
        {
            int tagNodeId = -1;
            if (!Int32.TryParse(nodeId, out tagNodeId))
                continue;
            // Loads relevant TagNode
            Node tagNode = new Node(tagNodeId);
            if (tagNode.GetProperty("uTagsyTagName") != null && tagNode.GetProperty("uTagsyTagName").Value.ToUpper().Contains(tag.ToUpper())) return currentNode;
        }

        return null;
    }

}