protected void Page_PreRender(object sender, EventArgs e)
    {
        try
        {
            int sFilter = 1;

            string s = Request["s"];

            int.TryParse(s, out sFilter);

            FileTypes fileType = (FileTypes)(short)sFilter;

            rpFiles.DataSource = BSPost.GetPosts(PostTypes.File, PostVisibleTypes.All, fileType, 0);
            rpFiles.DataBind();

            if (rpFiles.Items.Count == 0)
            {
                ltNoFile.Text = "<span style=\"padding:5px;margin:5px;text-align:center;display:block;border:1px solid #e7e7e7;background:#f4f4f4;font-weight:bold\">"
                                + Language.Admin["NoMedia"] + "</span>";
            }
        }
        catch (System.Exception ex)
        {
            ltNoFile.Text = ex.Message;
        }
    }
    /// <summary>
    /// Post's grid view data binding.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gvPosts_DataBinding(object sender, EventArgs e)
    {
        int iUserID = 0;

        int.TryParse(Request["UserID"], out iUserID);

        int iState = -1;

        if (!String.IsNullOrEmpty(Request["state"]))
        {
            int.TryParse(Request["state"], out iState);
        }

        PostStates postState;

        switch (iState)
        {
        case 1: postState = PostStates.Published;
            break;

        case 0: postState = PostStates.Draft;
            break;

        case 2: postState = PostStates.Removed;
            break;

        default: postState = PostStates.All;
            break;
        }


        string searchText = Request["Search"];

        List <BSPost> posts;

        GridView gv = (GridView)sender;

        if (!String.IsNullOrEmpty(searchText))
        {
            posts = User.IsInRole("editor") ? BSPost.GetPostsByTitle(searchText, Blogsa.ActiveUser.UserID) : BSPost.GetPostsByTitle(searchText, 0);
        }
        else if (User.IsInRole("editor"))
        {
            posts = BSPost.GetPostsByColumnValue("UserID", Blogsa.ActiveUser.UserID, 0, String.Empty, PostTypes.Article, postState);
        }
        else if (Request["UserID"] != null && iUserID != 0)
        {
            posts = BSPost.GetPostsByColumnValue("UserID", Blogsa.ActiveUser.UserID, 0, String.Empty, PostTypes.Article, postState);
        }
        else
        {
            posts = BSPost.GetPosts(PostTypes.Article, postState, 0);
        }

        gv.DataSource = posts;
        gv.Attributes.Add("totalItemCount", posts.Count.ToString(CultureInfo.InvariantCulture));
    }
Ejemplo n.º 3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        rpPopuler5Post.DataSource = BSPost.GetPosts(PostTypes.Article, PostStates.Published, 5);
        rpPopuler5Post.DataBind();

        if (rpPopuler5Post.Items.Count == 0)
        {
            ltNoData.Text = Language.Admin["NoPost"];
        }
    }
    protected void btnDeleteAllAutoSave_Click(object sender, EventArgs e)
    {
        List <BSPost> posts = BSPost.GetPosts(PostTypes.AutoSave, PostStates.Draft, 10);

        foreach (BSPost post in posts)
        {
            post.Remove();
        }
        Response.Redirect("AutoSaves.aspx");
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request["act"]) && Request["act"].Equals("delete"))
        {
            string strPostID = Request["PostID"];
            int    iPostID   = 0;

            int.TryParse(strPostID, out iPostID);

            if (iPostID > 0)
            {
                BSPost bsPost = BSPost.GetPost(iPostID);
                if (bsPost != null)
                {
                    bsPost.Remove();
                }
            }

            Response.Redirect("AutoSaves.aspx");
        }
        rpAutoSaves.DataSource = BSPost.GetPosts(PostTypes.AutoSave, PostStates.Draft, 10);
        rpAutoSaves.DataBind();
    }
Ejemplo n.º 6
0
    protected void gvPosts_DataBinding(object sender, EventArgs e)
    {
        GridView gv = (GridView)sender;

        gv.DataSource = BSPost.GetPosts(PostTypes.File, PostStates.All, 0);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        string tag      = Request["Tag"];
        string postID   = Request["PostID"];
        string postCode = Request["Code"];
        string category = Request["Category"];
        string fileID   = Request["FileID"];
        string langCode = Request["Language"];

        if (!string.IsNullOrEmpty(fileID))
        {
            postID = fileID;
        }

        int iPostID = 0;

        int.TryParse(postID, out iPostID);

        BSPost bsPost = null;

        if (iPostID != 0)
        {
            bsPost = BSPost.GetPost(iPostID);
        }
        else if (!string.IsNullOrEmpty(postCode))
        {
            bsPost = BSPost.GetPost(postCode);
        }

        if (bsPost != null)
        {
            if (bsPost.State == PostStates.Published && (bsPost.Type != PostTypes.AutoSave))
            {
                PostDetail = true;
                bsPost.ReadCount++;
                bsPost.Save();

                this.Page.Title = Blogsa.Title + " - " + bsPost.Title;
                BSHelper.AddHeader(this.Page, "keywords", bsPost.GetTagsWithComma());
                System.Web.UI.HtmlControls.HtmlGenericControl gc = new System.Web.UI.HtmlControls.HtmlGenericControl();
                gc.InnerHtml = bsPost.Content;

                BSHelper.AddHeader(this.Page, "description", gc.InnerText.Length > 160 ? gc.InnerText.Substring(0, 160) : gc.InnerText);
                BSHelper.AddHeader(this.Page, "robots", "index,follow");

                List <BSPost> posts = new List <BSPost>();
                posts.Add(bsPost);

                rpPosts.DataSource = posts;
                rpPosts.DataBind();
            }
        }
        else if (tag != null)
        {
            tag = BSHelper.CreateCode(tag);

            List <BSPost> posts     = BSPost.GetPostsByTerm(0, tag, TermTypes.Tag, PostTypes.Article, PostStates.Published);
            ObjectPager   pager     = new ObjectPager();
            int           pageCount = pager.PageCount(posts, 10);

            rpPosts.DataSource = pager.GetPage(posts, 0, 10);
            rpPosts.DataBind();
        }
        else if (category != null)
        {
            category = BSHelper.CreateCode(category);

            List <BSPost> posts     = BSPost.GetPostsByTerm(0, category, TermTypes.Category, PostTypes.Article, PostStates.Published);
            ObjectPager   pager     = new ObjectPager();
            int           pageCount = pager.PageCount(posts, 10);

            rpPosts.DataSource = pager.GetPage(posts, 0, 10);
            rpPosts.DataBind();
        }
        else
        {
            int iCurrentPage = 0;
            int.TryParse(Request["Page"], out iCurrentPage);
            if (iCurrentPage <= 0)
            {
                iCurrentPage = 1;
            }

            List <BSPost> posts = BSPost.GetPosts(PostTypes.Article, PostStates.Published, 0);

            Panel pnlPaging = new Panel();
            pnlPaging.CssClass = "paging";
            Literal ltPaging = new Literal();
            pnlPaging.Controls.Add(ltPaging);

            BSPlaceHolderPaging.Controls.Add(pnlPaging);

            rpPosts.DataSource = Data.Paging(posts, iCurrentPage, ltPaging);
            rpPosts.DataBind();
        }

        if (rpPosts.Items.Count == 0)
        {
            Literal l = new Literal();
            l.Text = Language.Get["NoWrite"];
            Controls.AddAt(0, l);
        }
    }
    // Call RSS
    public static void GetRSS(Page page, RssTypes type)
    {
        XmlTextWriter writer = new XmlTextWriter(page.Response.OutputStream, System.Text.Encoding.UTF8);

        WriteRSSPrologue(writer, type);

        List <BSPost> posts = new List <BSPost>();

        int intFeedCount = Blogsa.Settings["show_feed_count"] != null?Convert.ToInt32(Blogsa.Settings["show_feed_count"]) : 10;

        if (type == RssTypes.Comments)
        {
            List <BSComment> comments = BSComment.GetComments(CommentStates.Approved);
            if (comments.Count > 0)
            {
                foreach (BSComment comment in comments)
                {
                    BSPost bsPost = BSPost.GetPost(comment.PostID);
                    AddRSSItem(writer, bsPost.Title, bsPost.Link + "#Comments" + comment.CommentID,
                               comment.Content, comment.Date.ToString("EEE, dd MMMM yyyy HH:mm:ss Z"), comment.UserName);
                }
                WriteRSSClosing(writer);
                writer.Flush();
                writer.Close();
                page.Response.ContentEncoding = System.Text.Encoding.UTF8;
                page.Response.ContentType     = "text/xml";
                page.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                page.Response.End();
            }
        }
        else if (type == RssTypes.CommentsByPost)
        {
            List <BSComment> comments = BSComment.GetCommentsByPostID(Convert.ToInt32(HttpContext.Current.Request["PostID"]), CommentStates.Approved);
            if (comments.Count > 0)
            {
                BSPost bsPost = BSPost.GetPost(Convert.ToInt32(HttpContext.Current.Request["PostID"]));
                foreach (BSComment comment in comments)
                {
                    AddRSSItem(writer, bsPost.Title, bsPost.Link + "#Comments" + comment.CommentID,
                               comment.Content, comment.Date.ToString("EEE, dd MMMM yyyy HH:mm:ss Z"), comment.UserName);
                }
                WriteRSSClosing(writer);
                writer.Flush();
                writer.Close();
                page.Response.ContentEncoding = System.Text.Encoding.UTF8;
                page.Response.ContentType     = "text/xml";
                page.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                page.Response.End();
            }
        }
        else if (type == RssTypes.Posts)
        {
            posts = BSPost.GetPosts(PostTypes.Article, PostStates.Published, 10);
            if (posts.Count > 0)
            {
                foreach (BSPost post in posts)
                {
                    AddRSSItem(writer, post.Title, post.Link, post.Content, post.Date.ToString("EEE, dd MMMM yyyy HH:mm:ss Z"), post.UserName);
                }
                WriteRSSClosing(writer);
                writer.Flush();
                writer.Close();
                page.Response.ContentEncoding = System.Text.Encoding.UTF8;
                page.Response.ContentType     = "text/xml";
                page.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                page.Response.End();
            }
        }
    }