Ejemplo n.º 1
0
        public TransitPost(ISession session, DBlog.Data.Post o, bool hasaccess)
            : base(o.Id)
        {
            Title     = o.Title;
            Slug      = o.Slug;
            HasAccess = hasaccess;

            if (hasaccess)
            {
                mRawBody  = o.Body;
                Body      = Render(session, o.Body);
                BodyXHTML = RenderXHTML(session, o);
            }

            LoginId = o.Login.Id;

            if (o.PostImages != null && o.PostImages.Count > 0)
            {
                ImagesCount = o.PostImages.Count;

                if (hasaccess)
                {
                    ImageId = ((PostImage)TransitObject.GetRandomElement(o.PostImages)).Image.Id;
                }
            }

            // topics
            List <TransitTopic> topics = new List <TransitTopic>();

            if (o.PostTopics != null)
            {
                foreach (PostTopic postTopic in o.PostTopics)
                {
                    topics.Add(new TransitTopic(postTopic.Topic));
                }
            }
            mTopics = topics.ToArray();

            Created  = o.Created;
            Modified = o.Modified;

            CommentsCount = new CountQuery(session, typeof(PostComment), "PostComment")
                            .Add(Expression.Eq("Post.Id", o.Id))
                            .Execute <int>();

            Counter = TransitCounter.GetAssociatedCounter <Post, PostCounter>(
                session, o.Id);

            Publish = o.Publish;
            Display = o.Display;
            Sticky  = o.Sticky;
            Export  = o.Export;
        }
Ejemplo n.º 2
0
Archivo: Post.cs Proyecto: dblock/dblog
        public PostTest()
        {
            LoginTest login = new LoginTest();
            AddDependentObject(login);

            mPost = new Post();
            mPost.Login = login.Login;
            mPost.Created = mPost.Modified = DateTime.UtcNow;
            mPost.Body = Guid.NewGuid().ToString();
            mPost.Title = Guid.NewGuid().ToString();
            mPost.Publish = true;
            mPost.Display = true;
        }
Ejemplo n.º 3
0
        public static string RenderXHTML(ISession session, Post post)
        {
            StringBuilder content = new StringBuilder();

            if (!string.IsNullOrEmpty(post.Body))
            {
                content.Append("<div>");
                string body = Cutter.DeleteCut(post.Body);
                body = Render(session, body);
                body = Renderer.RenderEx(body, ConfigurationManager.AppSettings["url"], null);
                body = body.Replace("&", "&amp;");
                content.Append(body);
                content.Append("</div>");
            }

            content.Append("<div>");

            string link = string.IsNullOrEmpty(post.Slug)
                ? string.Format("./ShowPost.aspx?id={0}", post.Id)
                : string.Format("{0}", post.Slug);
            content.AppendFormat("<a href=\"{0}\">Read</a>",
                link);

            if (post.PostImages != null && post.PostImages.Count > 1)
            {
                content.AppendFormat(" | <a href=\"ShowPost.aspx?id={0}\">{1} Image{2}</a>",
                    post.Id, post.PostImages.Count, post.PostImages.Count != 1 ? "s" : string.Empty);
            }

            if (post.Created != post.Modified)
            {
                content.AppendFormat(" | Updated {0}",
                    post.Modified.ToString("d"));
            }

            if (post.PostImages != null && post.PostImages.Count > 0)
            {
                if (post.PostLogins == null || post.PostLogins.Count == 0)
                {
                    content.Append("<div style=\"margin-top: 10px;\">");
                    for (int i = 0; i < Math.Min(3, post.PostImages.Count); i++)
                    {
                        content.AppendFormat("<img src=\"ShowPicture.aspx?id={0}\">",
                            ((PostImage)post.PostImages[i]).Image.Id);
                    }
                    content.Append("</div>");
                }
            }

            content.Append("</div>");

            Uri root;
            if (Uri.TryCreate(ConfigurationManager.AppSettings["url"], UriKind.Absolute, out root))
            {
                return Tools.Web.Html.HtmlAbsoluteLinksWriter.Rewrite(
                    content.ToString(), root);
            }
            else
            {
                return content.ToString();
            }
        }
Ejemplo n.º 4
0
        public static bool GetAccess(ISession session, Post post, string ticket)
        {
            if (post.PostLogins == null || post.PostLogins.Count == 0)
                return true;

            if (string.IsNullOrEmpty(ticket))
                return false;

            if (ManagedLogin.IsAdministrator(session, ticket))
                return true;

            int login_id = ManagedLogin.GetLoginId(ticket);
            foreach (PostLogin pl in post.PostLogins)
            {
                if (pl.Login.Id == login_id)
                {
                    return true;
                }
            }

            return false;
        }
Ejemplo n.º 5
0
 public TransitPost(ISession session, DBlog.Data.Post o, string ticket)
     : this(session, o, GetAccess(session, o, ticket))
 {
 }