コード例 #1
0
        bool IMetaWeblog.UpdatePost(string postid, string username, string password,
            Post post, bool publish)
        {
            LocatePortal(Context.Request);
            DotNetNuke.Entities.Users.UserInfo ui = Authenticate(username, password);
            if (ui.UserID > 0)
            {

                Article a = Article.GetArticle(Convert.ToInt32(postid), _portalId, true, true,true);

                a.Description = post.description;
                a.ArticleText = post.description;
                a.Name = post.title;
                a.VersionDescription = Localization.GetString("MetaBlogApi", LocalResourceFile);

                var pc = new List<Publish.Category>();
                foreach (string s in post.categories)
                {
                    Publish.Category c = Publish.Category.GetCategory(s, PortalId);
                    pc.Add(c);
                }
                //remove all existing categories
                a.Relationships.Clear();
                //add the parent category
                if (pc.Count > 0)
                {
                    var irel = new ItemRelationship
                                   {
                                       RelationshipTypeId = Util.RelationshipType.ItemToParentCategory.GetId(),
                                       ParentItemId = pc[0].ItemId
                                   };
                    a.Relationships.Add(irel);

                }

                //add any extra categories
                if (pc.Count > 1)
                {
                    for (int i = 1; i < pc.Count; i++)
                    {
                        var irel = new ItemRelationship
                                       {
                                           RelationshipTypeId = Util.RelationshipType.ItemToRelatedCategory.GetId(),
                                           ParentItemId = pc[i].ItemId
                                       };
                        a.Relationships.Add(irel);
                    }
                }

                //remove existing tags
                a.Tags.Clear();

                //check for tags
                if (post.mt_keywords.Trim() != string.Empty)
                {
                    //split tags
                    foreach (Tag t in Tag.ParseTags(post.mt_keywords, _portalId))
                    {
                        ItemTag it = ItemTag.Create();
                        it.TagId = Convert.ToInt32(t.TagId, CultureInfo.InvariantCulture);
                        a.Tags.Add(it);
                    }
                }

                if (post.mt_excerpt != null && post.mt_excerpt.Trim() != string.Empty)
                {
                    a.Description = post.mt_excerpt;
                }

                // handle approval process
                if (ModuleBase.UseApprovalsForPortal(_portalId))
                {
                    if (ui.IsInRole(HostController.Instance.GetString(Utility.PublishAdminRole + _portalId)) || ui.IsSuperUser)
                    {
                        a.ApprovalStatusId = ApprovalStatus.Approved.GetId();
                    }
                    else if (ui.IsInRole(HostController.Instance.GetString(Utility.PublishAuthorRole + _portalId)))
                    {
                        a.ApprovalStatusId = ApprovalStatus.Waiting.GetId();
                    }
                }

                a.Save(ui.UserID);

                return true;
            }
            throw new XmlRpcFaultException(0, Localization.GetString("FailedToUpdatePost.Text", LocalResourceFile));
        }
コード例 #2
0
        ///<summary>
        /// Add a new blog post
        /// </summary>
        /// <param name="blogid">Blogid</param>
        /// <param name="username">username</param>
        /// <param name="password">password</param>
        /// <param name="post">post</param>
        /// <param name="publish">publish</param>
        string IMetaWeblog.AddPost(string blogid, string username, string password,
            Post post, bool publish)
        {
            LocatePortal(Context.Request);

            DotNetNuke.Entities.Users.UserInfo ui = Authenticate(username, password);
            if (ui != null)
            {
                //TODO: we need a default category for users, then we can allow theme detection in WLW
                var pc = new List<Publish.Category>();
                foreach (string s in post.categories)
                {
                    Publish.Category c = Publish.Category.GetCategory(s, PortalId);
                    pc.Add(c);
                }
                //This only works for the first category, how should we handle other categories?
                if (pc.Count < 1)
                {
                    Publish.Category c = Publish.Category.GetCategory(ModuleBase.DefaultCategoryForPortal(PortalId), PortalId);
                    pc.Add(c);
                }
                 if (pc.Count > 0)
                {
                //get description
                    //string description = post.description.Substring(0,post.description.IndexOf("
                    //look for <!--pagebreak-->

                    Article a = Article.Create(post.title, post.description,
                        post.description, ui.UserID, pc[0].ItemId, pc[0].ModuleId, pc[0].PortalId);
                    //TODO: check if dateCreated is a valid date
                    //TODO: date Created is coming in as UTC time
                    //TODO: re-enable Date created
                    //a.StartDate = post.dateCreated.ToString();
                    a.VersionDescription = Localization.GetString("MetaBlogApi", LocalResourceFile);

                    if (pc.Count > 1)
                    {
                        for (int i = 1; i < pc.Count; i++)
                        {
                            var irel = new ItemRelationship
                                           {
                                               RelationshipTypeId = Util.RelationshipType.ItemToRelatedCategory.GetId(),
                                               ParentItemId = pc[i].ItemId
                                           };
                            a.Relationships.Add(irel);
                        }
                    }

                    //check for tags
                    if (post.mt_keywords!=null && post.mt_keywords.Trim() != string.Empty)
                    {
                        //split tags
                        foreach (Tag t in Tag.ParseTags(post.mt_keywords, _portalId))
                        {
                            ItemTag it = ItemTag.Create();
                            it.TagId = Convert.ToInt32(t.TagId, CultureInfo.InvariantCulture);
                            a.Tags.Add(it);
                        }
                    }
                    if (post.mt_excerpt!=null && post.mt_excerpt.Trim() != string.Empty)
                    {
                        a.Description = post.mt_excerpt;
                    }

                    // handle approval process
                    if (ModuleBase.UseApprovalsForPortal(_portalId))
                    {
                        if (ui.IsInRole(HostController.Instance.GetString(Utility.PublishAdminRole + _portalId)) || ui.IsSuperUser)
                        {
                            a.ApprovalStatusId = ApprovalStatus.Approved.GetId();
                        }
                        else if (ui.IsInRole(HostController.Instance.GetString(Utility.PublishAuthorRole + _portalId)))
                        {
                            a.ApprovalStatusId = ApprovalStatus.Waiting.GetId();
                        }
                    }

                    a.Save(ui.UserID);
                    return a.ItemId.ToString();
                }
                throw new XmlRpcFaultException(0, Localization.GetString("PostCategoryFailed.Text", LocalResourceFile));
            }
            throw new XmlRpcFaultException(0, Localization.GetString("FailedAuthentication.Text", LocalResourceFile));
        }
コード例 #3
0
        Post IMetaWeblog.GetPost(string postid, string username, string password)
        {
            LocatePortal(Context.Request);
            DotNetNuke.Entities.Users.UserInfo ui = Authenticate(username, password);
            if (ui.UserID > 0)
            {
                var post = new Post();

                Article a = Article.GetArticle(Convert.ToInt32(postid), _portalId, true, false);

                post.description = a.ArticleText;
                post.title = a.Name;
                post.postid = a.ItemId.ToString();
                post.userid = a.AuthorUserId.ToString();
                post.dateCreated = Convert.ToDateTime(a.StartDate);

                int i = 0;
                foreach (ItemRelationship ir in a.Relationships)
                {
                    var c = new Category {categoryId = ir.ParentItemId.ToString()};
                    Publish.Category pcc = Publish.Category.GetCategory(ir.ParentItemId);
                    c.categoryName = pcc.Name;
                    post.categories[i] = c.ToString();
                    i++;
                }
                return post;
            }
            throw new XmlRpcFaultException(0, Localization.GetString("FailedAuthentication.Text", LocalResourceFile));
        }