示例#1
0
        public void ProcessRequest(HttpContext context)
        {
            Post post = null;

            try
            {
                int postID = int.Parse(_postID);
                post = new Data().GetPost(postID);
            }
            catch { }

            if (post != null && post.IsPublished)
            {
                string downloadFile = post.Custom("FileName");
                if (!string.IsNullOrEmpty(downloadFile))
                {
                    string localPath = context.Server.MapPath(downloadFile);
                    if (!string.IsNullOrEmpty(localPath) && File.Exists(localPath))
                    {
                        // Increment download count for post
                        DataHelper.UpdateMarketplaceStats(post.Id);

                        downloadFile = HttpUtility.UrlEncode(downloadFile).Replace("+", "%20");
                        context.Response.Clear();
                        context.Response.ContentType = "application/octet-stream";
                        context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", downloadFile));
                        context.Response.TransmitFile(localPath);
                        context.Response.End();
                        return;
                    }
                }
            }

            throw new HttpException(404, "Page not found");
        }
示例#2
0
        public override string RenderData()
        {
            StringBuilder sb = new StringBuilder("<ul>");
            Data data = new Data();
            PostCollection pc = CategoryId > 0
                                            ? data.PostsByCategory(
                                                    new CategoryController().GetCachedCategory(CategoryId, true), NumberOfPosts)
                                            : data.RecentPosts(NumberOfPosts);

            foreach (Post p in pc)
            {
                if (RolePermissionManager.GetPermissions(p.CategoryId, GraffitiUsers.Current).Read)
                    sb.AppendFormat("<li><a href=\"{0}\">{1}</a>{2}</li>\n", p.Url, p.Title, ShowExcerpt ? "<br />" + p.CustomExcerpt(100) : null);
            }

            sb.Append("</ul>\n");

            return sb.ToString();
        }
        public PostPage GetPost(string param)
        {
            var post = new Data().GetPost(param);

            if (post != null)
            {
                var postPage = new PostPage();

                postPage.PostId = post.Id;
                postPage.CategoryID = post.CategoryId;
                postPage.CategoryName = new CategoryController().GetCachedCategory(post.CategoryId, false).LinkName;
                postPage.PostName = post.Name;
                postPage.Name = post.Name;
                postPage.MetaDescription = post.MetaDescription;
                postPage.MetaKeywords = post.MetaKeywords;

                return postPage;
            }

            return null;
        }
示例#4
0
        /// <summary>
        /// Renders the view.
        /// </summary>
        /// <param name="view">The view.</param>
        /// <param name="context">The context.</param>
        private void RenderView(string view, ControllerContext context)
        {
            context["request"] = context.Request;
            context["response"] = context.Response;
            context["url"] = context.Request.RawUrl;
            context["urls"] = new Urls();
            context["util"] = new UtilWrapper();
            context["macros"] = new Macros();
            context["data"] = new Data();
            context["site"] = SiteSettings.Get();

            context.Response.ClearContent();
            context.Response.ContentType = contentType;
            if (!String.IsNullOrEmpty(filename))
                context.Response.AddHeader("Content-Disposition", new ContentDisposition { FileName = filename }.ToString());
            TemplateEngine.Evaluate(context.Response.Output, view, context);
            context.Response.End();
        }
示例#5
0
        protected override void OnLoad(EventArgs e)
        {
            SiteSettings settings = SiteSettings.Get();
            CommentCollection cc = new Data().RecentComments(Util.PageSize);

            DateTime lastModified = DateTime.Now;
            if (cc.Count > 0)
            {
                string lastMod = Context.Request.Headers["If-Modified-Since"];
                if (lastMod != null)
                {
                    if (lastMod == cc[0].Published.AddHours(-1 * settings.TimeZoneOffSet).ToUniversalTime().ToString("r"))
                    {
                        Context.Response.StatusCode = 304;
                        Context.Response.Status = "304 Not Modified";
                        Context.Response.End();
                    }
                }
                lastModified = cc[0].Published.AddHours(-1 * settings.TimeZoneOffSet);
                Context.Response.Clear();
                Context.Response.Cache.SetCacheability(HttpCacheability.Public);
                Context.Response.Cache.SetLastModified(lastModified);
                Context.Response.Cache.SetETag(lastModified.ToString());
            }

            Macros macros = new Macros();

            StringWriter sw = new StringWriter();
            sw.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
            XmlTextWriter writer = new XmlTextWriter(sw);

            writer.WriteStartElement("rss");
            writer.WriteAttributeString("version", "2.0");
            writer.WriteAttributeString("xmlns:dc", "http://purl.org/dc/elements/1.1/");

            writer.WriteStartElement("channel");
            writer.WriteElementString("title", settings.Title + ": All Comments");
            writer.WriteElementString("link", macros.FullUrl(new Urls().Home));
            writer.WriteElementString("description", settings.TagLine);
            writer.WriteElementString("generator", SiteSettings.VersionDescription);
            writer.WriteElementString("lastBuildDate", lastModified.AddHours(-1 * settings.TimeZoneOffSet).ToUniversalTime().ToString("r"));

            string baseUrl = SiteSettings.BaseUrl;
            foreach (Comment comment in cc)
            {
                string link = macros.FullUrl(comment.Url);
                string body = Util.FullyQualifyRelativeUrls(comment.Body, baseUrl);
                if (comment.IsTrackback)
                    body = string.Format("{0}\n<br />\nTrackback url: {1}", body, comment.WebSite);

                writer.WriteStartElement("item");
                writer.WriteElementString("title", HttpUtility.HtmlDecode(comment.Title));
                writer.WriteElementString("link", link);
                writer.WriteElementString("pubDate", comment.Published.AddHours(-1 * settings.TimeZoneOffSet).ToUniversalTime().ToString("r"));

                writer.WriteStartElement("guid");
                writer.WriteAttributeString("isPermaLink", "true");
                writer.WriteString(link);
                writer.WriteEndElement();

                writer.WriteElementString("dc:creator", comment.Name);
                writer.WriteElementString("description", body);

                writer.WriteEndElement(); // End Item
            }

            writer.WriteEndElement(); // End Channel
            writer.WriteEndElement(); // End Document

            // save XML into response
            Context.Response.ContentEncoding = System.Text.Encoding.UTF8;
            Context.Response.ContentType = "application/rss+xml";
            Context.Response.Write(sw.ToString());
        }
示例#6
0
        private Post GetPostFromUrl(string url)
        {
            Post post = null;

            if (!string.IsNullOrEmpty(url))
            {
                string[] urlSegments = url.Split('/');
                if (urlSegments != null && urlSegments.Length > 1)
                {
                    string postName = urlSegments[urlSegments.Length - 2];
                    if (!string.IsNullOrEmpty(postName))
                    {
                        post = new Data().GetPost(postName);
                    }
                }
            }

            return post;
        }
示例#7
0
        private IEnumerable GetPosts()
        {
            PostCollection posts = new Data().PostsByCategory(_categoryId, 100);

            if (posts != null && posts.Count > 0)
            {
                foreach (Post p in posts)
                {
                    yield return p;
                }
            }
        }
示例#8
0
        /// <summary>
        /// Creates a list of links which can be used to build custom sub category navigation.
        /// </summary>
        /// <param name="usePostsIfNoChildCategories">If the current top-level category does not have any child categories, should posts from that category be returned as links instead?</param>
        /// <returns></returns>
        public List<Link> NavigationSubLinks(bool usePostsIfNoChildCategories)
        {
            List<Link> links = new List<Link>();

            Category currentCategory = null;
            TemplatedThemePage ttp = HttpContext.Current.Handler as TemplatedThemePage;
            CategoryCollection categories = new CategoryCollection();

            if (ttp != null)
            {
                // Is this page a category?
                // Note: Post pages expose their categories and do not require a seperate lookup
                if (ttp.CategoryID > 0)
                {
                    // This could be a subcategory. Since we do not expose subcategories via NavBar(),
                    // we should mark the parent (if it exists) as selected item
                    currentCategory = new CategoryController().GetCachedCategory(ttp.CategoryID, true);
                    if (currentCategory != null)
                    {
                        // If the current category has a parent, we have to assume it's a child category.
                        // In which case, we need to list out all the children of the parent.
                        if (currentCategory.ParentId > 0)
                        {
                            Category parentCategory = new CategoryController().GetCachedCategory(currentCategory.ParentId, true);
                            categories = parentCategory.Children;
                        }
                        else
                        {
                            categories = currentCategory.Children;
                        }

                        if (categories != null && categories.Count > 0)
                        {
                            foreach (Category category in categories)
                            {
                                Link link = new Link();
                                link.IsSelected = (currentCategory.Id == category.Id);
                                link.Text = category.Name;
                                link.CategoryId = category.Id;
                                link.NavigationType = DynamicNavigationType.Category;
                                link.Url = category.Url;
                                links.Add(link);
                            }
                        }
                        else if (usePostsIfNoChildCategories && currentCategory.PostCount > 0)
                        {
                            PostCollection posts = new Data().PostsByCategory(currentCategory, 10);
                            foreach (Post post in posts)
                            {
                                Link link = new Link();
                                link.IsSelected = (ttp.PostId == post.Id);
                                link.Text = post.Title;
                                link.CategoryId = post.Id;
                                link.PostId = post.Id;
                                link.NavigationType = DynamicNavigationType.Post;
                                link.Url = post.Url;
                                links.Add(link);
                            }
                        }
                    }
                }
            }

            return links;
        }
示例#9
0
        /// <summary>
        /// Renders an unordred list of recent (published) comments
        /// </summary>
        /// <param name="numberOfComments"></param>
        /// <returns></returns>
        public string ULRecentComments(int numberOfComments)
        {
            CommentCollection cc = new Data().RecentComments(numberOfComments);

            StringBuilder sb = new StringBuilder();
            if (cc.Count > 0)
            {
                foreach (Comment c in cc)
                {
                    sb.AppendFormat("<li><a href=\"{0}\" title=\"{2} on {1} at {3}\">{2} on {1}</a></li>\n", c.Url, c.Post.Title,
                                         c.User.ProperName, c.Published);
                }
            }

            return sb.ToString();
        }