Ejemplo n.º 1
0
        public string UpdateEntry(Entry entry, string username, string password)
        {
            if (SiteSecurity.Login(username, password).Role != "admin")
            {
                throw new Exception("Invalid Password");
            }
            foreach (DayEntry day in data.Days)
            {
                if (day.Date == entry.Created.Date)
                {
                    day.Load();

                    foreach (Entry found in day.Entries)
                    {
                        if (found.EntryId == entry.EntryId)
                        {
                            found.Categories  = entry.Categories;
                            found.Content     = entry.Content;
                            found.Title       = entry.Title;
                            found.Description = entry.Description;
                            found.Modify();

                            day.Save();
                            data.IncrementEntryChange();
                            BlogXUtils.PingWeblogsCom();

                            return(entry.EntryId);
                        }
                    }
                }
            }

            return("not found");
        }
Ejemplo n.º 2
0
 private void Page_Load(object sender, System.EventArgs e)
 {
     BlogXUtils.TrackReferrer(Request, Server);
     if (!IsPostBack)
     {
     }
 }
Ejemplo n.º 3
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            title.Controls.Clear();
            title.Controls.Add(new LiteralControl(SiteConfig.GetSiteConfig().Title));

            BlogXUtils.TrackReferrer(Request, Server);
            blogCal.SelectedDate = StartDate;
            blogCal.VisibleDate  = StartDate;
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            BlogXUtils.TrackReferrer(Request, Server);

            EntryIdCache ecache = new EntryIdCache();

            ecache.Ensure(data);

            Control root    = content;
            string  entryId = Request.QueryString["guid"];

            if (entryId != null && entryId.Length > 0)
            {
                entryId = entryId.ToUpper();
            }
            else
            {
                entryId = Request.PathInfo.Substring(1).ToUpper();
            }
            DateTime found = new DateTime();

            foreach (EntryIdCacheEntry ece in ecache.Entries)
            {
                if (ece.EntryId.ToUpper() == entryId)
                {
                    found = ece.Date;
                    break;
                }
            }

            foreach (DayEntry day in data.Days)
            {
                if (day.Date == found)
                {
                    day.Load();
                    DayExtra extra = data.GetDayExtra(day.Date);
                    foreach (Entry entry in day.Entries)
                    {
                        if (entryId.ToUpper() == entry.EntryId.ToUpper())
                        {
                            EntryView view = (EntryView)LoadControl("EntryView.ascx");
                            view.DateFormat = "MM/dd/yyyy h:mm tt";
                            view.Data       = data;
                            view.Extra      = extra;
                            view.Entry      = entry;
                            root.Controls.Add(view);

                            break;
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void save_Click(object sender, System.EventArgs e)
        {
            if (SiteSecurity.IsInRole("admin"))
            {
                BlogXData data = new BlogXData();

                bool added = false;

                Entry entry = new Entry();
                entry.Initialize();
                entry.Title       = entryTitle.Text;
                entry.Description = entryAbstract.Text;
                entry.Content     = entryContent.Text;
                entry.Categories  = entryCategories.Text;

                foreach (DayEntry day in data.Days)
                {
                    if (day.Date == entry.Created.Date)
                    {
                        added = true;
                        day.Load();
                        day.Entries.Add(entry);
                        day.Save();
                        data.IncrementEntryChange();
                        BlogXUtils.PingWeblogsCom();
                        break;
                    }
                }
                if (!added)
                {
                    DayEntry newDay = new DayEntry();
                    newDay.Date = entry.Created.Date;
                    newDay.Entries.Add(entry);
                    newDay.Save();

                    data.IncrementEntryChange();
                    BlogXUtils.PingWeblogsCom();
                }

                entryTitle.Text      = "";
                entryAbstract.Text   = "";
                entryContent.Text    = "";
                entryCategories.Text = "";

                Response.Redirect("default.aspx", false);
            }
        }
Ejemplo n.º 6
0
        public static LogDataItemCollection GetReferrerLog(DateTime date)
        {
            LogDataItemCollection logs = new LogDataItemCollection();

            string log    = BlogXUtils.GetReferrerLogText(HttpContext.Current.Server, DateTime.Now);
            Regex  parser = new Regex(@"e2\ttime(?<time>.*)\turl\t(?<url>.*)\turlreferrer\t(?<urlreferrer>.*)\tuseragent\t(?<useragent>.*)");

            foreach (Match match in parser.Matches(log))
            {
                LogDataItem item = new LogDataItem();
                item.Requested    = DateTime.Parse(match.Groups["time"].Value);
                item.UrlRequested = match.Groups["url"].Value;
                item.UrlReferrer  = match.Groups["urlreferrer"].Value;
                item.UserAgent    = match.Groups["useragent"].Value;
                logs.Add(item);
            }

            return(logs);
        }
Ejemplo n.º 7
0
        public string CreateEntry(Entry entry, string username, string password)
        {
            if (SiteSecurity.Login(username, password).Role != "admin")
            {
                throw new Exception("Invalid Password");
            }
            bool added = false;

            // ensure that the entryId was filled in
            //
            if (entry.EntryId == null || entry.EntryId.Length == 0)
            {
                entry.EntryId = Guid.NewGuid().ToString();
            }

            foreach (DayEntry day in data.Days)
            {
                if (day.Date == entry.Created.Date)
                {
                    added = true;
                    day.Load();
                    day.Entries.Add(entry);
                    day.Save();
                    data.IncrementEntryChange();
                    BlogXUtils.PingWeblogsCom();
                    break;
                }
            }
            if (!added)
            {
                DayEntry newDay = new DayEntry();
                newDay.Date = entry.Created.Date;
                newDay.Entries.Add(entry);
                newDay.Save();

                data.IncrementEntryChange();
                BlogXUtils.PingWeblogsCom();
            }

            return(entry.EntryId);
        }
Ejemplo n.º 8
0
        public void DeleteEntry(string entryId, string username, string password)
        {
            if (SiteSecurity.Login(username, password).Role != "admin")
            {
                throw new Exception("Invalid Password");
            }
            EntryIdCache ecache = new EntryIdCache();

            ecache.Ensure(data);

            DateTime found = new DateTime();

            foreach (EntryIdCacheEntry ece in ecache.Entries)
            {
                if (ece.EntryId == entryId)
                {
                    found = ece.Date;
                    break;
                }
            }

            foreach (DayEntry day in data.Days)
            {
                if (day.Date == found)
                {
                    day.Load();

                    for (int i = 0; i < day.Entries.Count; i++)
                    {
                        if (day.Entries[i].EntryId == entryId)
                        {
                            day.Entries.RemoveAt(i);
                            day.Save();
                            BlogXUtils.PingWeblogsCom();
                            return;
                        }
                    }
                }
            }
        }
Ejemplo n.º 9
0
        private void CategoryList_PreRender(object sender, System.EventArgs e)
        {
            CategoryCache cache = new CategoryCache();

            cache.Ensure(data);

            HtmlGenericControl section = new HtmlGenericControl("div");

            section.Attributes["class"] = "section";
            this.Controls.Add(section);

            HtmlGenericControl heading = new HtmlGenericControl("h3");

            heading.Controls.Add(new LiteralControl("Categories"));
            section.Controls.Add(heading);

            HtmlGenericControl list = new HtmlGenericControl("ul");

            section.Controls.Add(list);

            foreach (CategoryCacheEntry catEntry in cache.Entries)
            {
                HtmlGenericControl item = new HtmlGenericControl("li");
                list.Controls.Add(item);

                HyperLink catLink = new HyperLink();
                catLink.Text        = catEntry.Name;
                catLink.NavigateUrl = BlogXUtils.RelativeToRoot("CategoryView.aspx/" + catEntry.Name);
                item.Controls.Add(catLink);
                item.Controls.Add(new LiteralControl(" ("));
                HyperLink rssLink = new HyperLink();
                rssLink.Text        = "rss";
                rssLink.NavigateUrl = BlogXUtils.RelativeToRoot("BlogXBrowsing.asmx/GetRssCategory?categoryName=" + catEntry.Name);
                item.Controls.Add(rssLink);
                item.Controls.Add(new LiteralControl(")"));
            }
        }
        private void CommentView_PreRender(object sender, System.EventArgs e)
        {
            string       entryId = (string)ViewState["entryId"];
            EntryIdCache ecache  = new EntryIdCache();

            ecache.Ensure(data);
            Control root = comments;

            DateTime found = new DateTime();

            foreach (EntryIdCacheEntry ece in ecache.Entries)
            {
                if (ece.EntryId.ToUpper() == entryId)
                {
                    found   = ece.Date;
                    entryId = ece.EntryId;
                    break;
                }
            }

            bool     obfuscateEmail = SiteConfig.GetSiteConfig().ObfuscateEmail;
            DayExtra extra          = data.GetDayExtra(found);

            extra.Load();

            foreach (DayEntry day in data.Days)
            {
                if (day.Date == found)
                {
                    day.Load();
                    foreach (Entry entry in day.Entries)
                    {
                        if (entry.EntryId == entryId)
                        {
                            EntryView entryView = (EntryView)LoadControl("EntryView.ascx");
                            entryView.Data  = data;
                            entryView.Entry = entry;
                            entryView.Extra = extra;
                            comments.Controls.Add(entryView);
                        }
                    }
                }
            }

            commentSpamGuard.Visible = SiteConfig.GetSiteConfig().CommentSpamGuard;
            if (SiteConfig.GetSiteConfig().CommentSpamGuard)
            {
                System.Security.Cryptography.RandomNumberGenerator r = System.Security.Cryptography.RandomNumberGenerator.Create();
                byte[] randomData = new byte[4];
                r.GetBytes(randomData);
                int code = 0;
                for (int i = 0; i < randomData.Length; i++)
                {
                    code += randomData[i];
                }
                code = code % SiteConfig.GetCommentWords().Length;
                securityWordImage.ImageUrl = BlogXUtils.RelativeToRoot("verifyimagegen.ashx?code=" + code);
                ViewState["spamCode"]      = code;
            }


            foreach (Comment c in extra.GetCommentsFor(entryId))
            {
                SingleCommentView view = (SingleCommentView)LoadControl("SingleCommentView.ascx");
                view.Comment        = c;
                view.ObfuscateEmail = obfuscateEmail;
                root.Controls.Add(view);
            }
        }
 private void Page_Load(object sender, System.EventArgs e)
 {
     BlogXUtils.AddContentTo(Request.QueryString["path"], content);
 }
Ejemplo n.º 12
0
 private void Page_Load(object sender, System.EventArgs e)
 {
     BlogXUtils.AddContentTo(path, this);
 }
Ejemplo n.º 13
0
 public LogDataItemCollection GetReferrerLog(DateTime date)
 {
     return(BlogXUtils.GetReferrerLog(date));
 }
Ejemplo n.º 14
0
        private XmlNode GetRssCore(string category, int maxDayCount)
        {
            BlogXData.Resolver = new ResolveFileCallback(ResolvePath);

            RssRoot    r      = new RssRoot();
            RssChannel ch     = new RssChannel();
            SiteConfig config = SiteConfig.GetSiteConfig();

            ch.Title          = config.Title;
            ch.Link           = config.Root;
            ch.Copyright      = config.Copyright;
            ch.ManagingEditor = config.Contact;
            ch.WebMaster      = config.Contact;
            r.Channels.Add(ch);

            BlogXData       data    = new BlogXData();
            EntryCollection entries = BuildEntries(data, category, maxDayCount);

            using (StreamWriter sw = new StreamWriter(Server.MapPath(Path.Combine("logs", "dump.txt"))))
            {
                DateTime latest = new DateTime(0);

                foreach (Entry entry in entries)
                {
                    DateTime created = entry.Created;
                    if (created > latest)
                    {
                        latest = created;
                    }
                }

                HttpRequest  req         = Context.Request;
                HttpResponse res         = Context.Response;
                bool         notModified = false;

                // Check the request's if-modified-since field.
                // If it matches our last build date, then the
                // caller already has the most recent data and
                // we can abort the whole process with an
                // error 304: Not Modified

                string ifModifiedSince = req.Headers["if-modified-since"];
                if (ifModifiedSince != null)
                {
                    DateTime modDate = latest;
                    modDate = new DateTime(modDate.Year, modDate.Month, modDate.Day, modDate.Hour, modDate.Minute, modDate.Second);
                    try
                    {
                        DateTime ifModDate = DateTime.Parse(ifModifiedSince);
                        notModified = (ifModDate == modDate);
                    }
                    catch {}
                }

                // Also check the request for an etag header and
                // see if it maches our date.  The rules are if
                // both headers are there, they both have to match.  But,
                // if only one header is there only it has to match.

                string etag = req.Headers["etag"];
                if (etag != null)
                {
                    notModified = (etag.Equals(latest.Ticks.ToString()));
                }

                if (notModified)
                {
                    res.StatusCode      = 304;
                    res.SuppressContent = true;
                    return(null);
                }

                // Either no one used if-modified-since or we have
                // new data.  Record the last modified time and
                // etag in the http header for next time.

                res.Cache.SetLastModified(latest);
                res.Cache.SetETag(latest.Ticks.ToString());
            }

            BlogXUtils.TrackReferrer(Context.Request, Server);

            foreach (Entry entry in entries)
            {
                RssItem item = new RssItem();
                item.Title    = entry.Title;
                item.Guid     = item.Link = new Uri(new Uri(config.Root), " PermaLink.aspx/" + entry.EntryId).ToString();
                item.Comments = new Uri(new Uri(config.Root), "CommentView.aspx/" + entry.EntryId).ToString();
                if (entry.Categories != null && entry.Categories.Length > 0)
                {
                    item.Category = entry.GetSplitCategories()[0];
                }
                item.PubDate = entry.Created.ToString("R");
                if (ch.LastBuildDate == null || ch.LastBuildDate.Length == 0)
                {
                    ch.LastBuildDate = item.PubDate;
                }
                if (entry.Description != null && entry.Description.Trim().Length > 0)
                {
                    item.Description = entry.Description;
                }
                else
                {
                    item.Description = entry.Content;
                }

                XmlDocument doc2 = new XmlDocument();
                try
                {
                    doc2.LoadXml(entry.Content);
                    item.Body = (XmlElement)doc2.SelectSingleNode("//*[local-name() = 'body'][namespace-uri()='http://www.w3.org/1999/xhtml']");
                }
                catch {}

                ch.Items.Add(item);
            }

            XmlSerializer ser    = new XmlSerializer(typeof(RssRoot));
            StringWriter  writer = new StringWriter();

            ser.Serialize(writer, r);

            XmlDocument doc = new XmlDocument();

            doc.Load(new StringReader(writer.ToString()));

            return(doc.FirstChild.NextSibling);
        }
Ejemplo n.º 15
0
        private void WebForm1_PreRender(object sender, System.EventArgs e)
        {
            Control root = content;

            SiteConfig config   = SiteConfig.GetSiteConfig();
            string     siteRoot = config.Root.ToUpper();

            Hashtable data = new Hashtable();

            foreach (LogDataItem log in BlogXUtils.GetReferrerLog(DateTime.Now))
            {
                bool exclude = false;
                if (log.UrlReferrer != null)
                {
                    exclude = log.UrlReferrer.ToUpper().StartsWith(siteRoot);
                }
                if (!exclude)
                {
                    if (!data.Contains(log.UrlReferrer))
                    {
                        data[log.UrlReferrer] = 0;
                    }
                    data[log.UrlReferrer] = ((int)data[log.UrlReferrer]) + 1;
                }
            }

            ArrayList list = new ArrayList(data.Count);

            foreach (DictionaryEntry de in data)
            {
                list.Add(new RefItem(de.Key.ToString(), (int)de.Value));
            }

            list.Sort(new RefItem.Comparer());

            int   total = 0;
            Table table = new Table();

            foreach (RefItem item in list)
            {
                TableRow row = new TableRow();
                row.Cells.Add(new TableCell());
                row.Cells.Add(new TableCell());

                HyperLink link = new HyperLink();
                string    text = item.url;
                if (text != null && text.Length > 0)
                {
                    if (text.Length > 40)
                    {
                        text = text.Substring(0, 40) + "...";
                    }
                }
                else
                {
                    text = "(none)";
                }
                link.Text        = text;
                link.NavigateUrl = item.url.ToString();
                row.Cells[0].Controls.Add(link);
                row.Cells[1].Text = item.count.ToString();
                total            += item.count;

                table.Rows.Add(row);
            }

            TableRow totalRow = new TableRow();

            totalRow.Cells.Add(new TableCell());
            totalRow.Cells.Add(new TableCell());
            totalRow.Cells[0].Text = "Total";
            totalRow.Cells[1].Text = total.ToString();
            table.Rows.Add(totalRow);

            root.Controls.Add(table);
        }
Ejemplo n.º 16
0
        private void Page_PreRender(object sender, System.EventArgs e)
        {
            Control            root         = this;
            HtmlGenericControl entryControl = new HtmlGenericControl("div");

            entryControl.Attributes["class"] = "entry";
            root.Controls.Add(entryControl);

            HtmlGenericControl entryTitle = new HtmlGenericControl("h3");

            entryTitle.Attributes["class"] = "entryTitle";
            if (EntryTitleAsLink)
            {
                HyperLink entryTitleLink = new HyperLink();
                entryTitleLink.NavigateUrl = BlogXUtils.RelativeToRoot("PermaLink.aspx/" + entry.EntryId);
                entryTitleLink.Text        = entry.Title;
                entryTitle.Controls.Add(entryTitleLink);
            }
            else
            {
                entryTitle.Controls.Add(new LiteralControl(entry.Title));
            }
            entryControl.Controls.Add(entryTitle);

            HtmlGenericControl entryBody = new HtmlGenericControl("div");

            entryBody.Attributes["class"] = "entryBody";
            entryBody.Controls.Add(new LiteralControl(entry.Content));
            entryControl.Controls.Add(entryBody);

            HtmlGenericControl entryFooter = new HtmlGenericControl("p");

            entryFooter.Attributes["class"] = "entryFooter";
            entryControl.Controls.Add(entryFooter);

            HyperLink entryDate = new HyperLink();

            entryDate.CssClass    = "permalink";
            entryDate.NavigateUrl = BlogXUtils.RelativeToRoot("PermaLink.aspx/" + entry.EntryId);
            entryDate.Text        = entry.Created.ToString(dateFormat);
            entryFooter.Controls.Add(entryDate);


            if (SiteConfig.GetSiteConfig().AllowComments)
            {
                entryFooter.Controls.Add(new LiteralControl(" | "));

                extra.Load();
                CommentCollection  entryComments = extra.GetCommentsFor(entry.EntryId);
                HtmlGenericControl comments      = new HtmlGenericControl("span");
                comments.Attributes["class"] = "comments";

                if (entryComments.Count == 0)
                {
                    HyperLink comment = new HyperLink();
                    comment.Text        = "Add comment";
                    comment.NavigateUrl = BlogXUtils.RelativeToRoot("CommentView.aspx/" + entry.EntryId);
                    comments.Controls.Add(comment);
                }
                else
                {
                    HyperLink comment = new HyperLink();
                    comment.Text        = "Comments [" + entryComments.Count + "]";
                    comment.NavigateUrl = BlogXUtils.RelativeToRoot("CommentView.aspx/" + entry.EntryId);
                    comments.Controls.Add(comment);
                }
                entryFooter.Controls.Add(comments);
            }


            if (entry.Categories != null && entry.Categories.Length > 0)
            {
                entryFooter.Controls.Add(new LiteralControl(" | "));

                HtmlGenericControl categories = new HtmlGenericControl("span");
                categories.Attributes["class"] = "categories";

                foreach (string cat in entry.GetSplitCategories())
                {
                    categories.Controls.Add(new LiteralControl(" #"));

                    HyperLink category = new HyperLink();
                    category.Text        = cat;
                    category.NavigateUrl = BlogXUtils.RelativeToRoot("CategoryView.aspx/" + cat);
                    categories.Controls.Add(category);
                }

                entryFooter.Controls.Add(categories);
            }
        }