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;
                        }
                    }
                }
            }
        }
예제 #2
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;
                        }
                    }
                }
            }
        }
        private void add_Click(object sender, System.EventArgs e)
        {
            if (SiteConfig.GetSiteConfig().CommentSpamGuard)
            {
                string word = SiteConfig.GetCommentWords()[(int)ViewState["spamCode"]];
                if (!word.Equals(securityWord.Text))
                {
                    // UNDONE : Should show an error page...
                    //
                    return;
                }
            }

            string entryId = ViewState["entryId"].ToString().ToUpper();

            if (rememberMe.Checked)
            {
                Response.Cookies.Add(new HttpCookie("name", name.Text));
                Response.Cookies.Add(new HttpCookie("email", email.Text));
                Response.Cookies.Add(new HttpCookie("homepage", homepage.Text));
            }
            EntryIdCache ecache = new EntryIdCache();

            ecache.Ensure(data);

            DateTime dateFound = new DateTime();
            bool     found     = false;

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

            if (found)
            {
                if (SiteConfig.GetSiteConfig().AllowComments)
                {
                    DayExtra extra = data.GetDayExtra(dateFound);
                    extra.Load();
                    Comment c = new Comment();
                    c.Initialize();
                    c.Author         = name.Text;
                    c.AuthorEmail    = email.Text;
                    c.AuthorHomepage = homepage.Text;
                    c.Content        = Server.HtmlEncode(comment.Text);
                    c.TargetEntryId  = entryId;
                    extra.Comments.Add(c);
                    extra.Save();

                    data.IncrementExtraChange();
                }

                name.Text     = "";
                email.Text    = "";
                homepage.Text = "";
                comment.Text  = "";
                Response.Redirect("default.aspx", false);
            }
        }
        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);
            }
        }
예제 #5
0
        static int Main(string[] args)
        {
            Console.WriteLine("Radio Data Importer");
            Console.WriteLine("");

            foreach (string arg in args)
            {
                if (arg.Length > 6 && arg.ToLower().StartsWith("/from:"))
                {
                    from = arg.Substring(6).Trim();
                    if (from[0] == '\"' && from[from.Length] == '\"')
                    {
                        from = from.Substring(1, from.Length - 2);
                    }
                }
                else if (arg.Length > 4 && arg.ToLower().StartsWith("/to:"))
                {
                    to = arg.Substring(4).Trim();
                    if (to[0] == '\"' && to[from.Length] == '\"')
                    {
                        to = to.Substring(1, to.Length - 2);
                    }
                }
                else
                {
                    break;
                }
            }

            if (from == null || to == null || from.Length == 0 || to.Length == 0)
            {
                Console.WriteLine("Usage: blogcmd /from:<radio directory> /to:<output directory>");
                Console.WriteLine("");
                return(-1);
            }


            BlogXData.Resolver = new ResolveFileCallback(FileSystemResolver);

            Console.WriteLine("Importing entries...");

            ArrayList tables = new ArrayList();

            XmlDocument   masterDoc = new XmlDocument();
            StringBuilder sb        = new StringBuilder();

            sb.Append("<tables>");

            foreach (FileInfo file in new DirectoryInfo(from).GetFiles("*.xml"))
            {
                XmlDocument entry = new XmlDocument();
                entry.Load(file.FullName);
                sb.Append(entry.FirstChild.NextSibling.OuterXml);
            }
            sb.Append("</tables>");

            masterDoc.Load(new StringReader(sb.ToString()));

            foreach (XmlNode node in masterDoc.FirstChild)
            {
                RadioTable table = new RadioTable();
                table.Name = node.Attributes["name"].Value;
                foreach (XmlNode child in node)
                {
                    switch (child.Name)
                    {
                    case "date":
                        table.Data[child.Attributes["name"].Value] = DateTime.Parse(child.Attributes["value"].Value);
                        break;

                    case "boolean":
                        table.Data[child.Attributes["name"].Value] = bool.Parse(child.Attributes["value"].Value);
                        break;

                    case "string":
                        table.Data[child.Attributes["name"].Value] = child.Attributes["value"].Value;
                        break;

                    case "table":
                        if (child.Attributes["name"].Value == "categories")
                        {
                            foreach (XmlNode catNode in child)
                            {
                                if (catNode.Name == "boolean" && catNode.Attributes["value"].Value == "true")
                                {
                                    if (table.Data.Contains("categories"))
                                    {
                                        table.Data["categories"] = (string)table.Data["categories"] + ";" + catNode.Attributes["name"].Value;
                                    }
                                    else
                                    {
                                        table.Data["categories"] = catNode.Attributes["name"].Value;
                                    }
                                }
                            }
                        }
                        break;
                    }
                }
                tables.Add(table);
            }

            BlogXData data = new BlogXData();

            foreach (RadioTable table in tables)
            {
                DateTime date     = table.When.Date;
                DayEntry dayEntry = null;
                foreach (DayEntry target in data.Days)
                {
                    if (target.Date == date)
                    {
                        dayEntry = target;
                        break;
                    }
                }
                if (dayEntry == null)
                {
                    dayEntry      = new DayEntry();
                    dayEntry.Date = date;
                    data.Days.Add(dayEntry);
                }

                Entry entry = new Entry();
                entry.Created    = table.When;
                entry.Title      = table.Title;
                entry.Content    = table.Text;
                entry.Categories = table.Categories;
                entry.EntryId    = table.UniqueId;
                dayEntry.Entries.Add(entry);
                data.IncrementEntryChange();
            }

            Console.WriteLine("Saving entries...");
            foreach (DayEntry day in data.Days)
            {
                day.Save();
            }

            Console.WriteLine("Creating comment cache...");
            CategoryCache cache = new CategoryCache();

            cache.Ensure(data);

            Console.WriteLine("Creating entry cache...");
            EntryIdCache ecache = new EntryIdCache();

            ecache.Ensure(data);

            return(0);
        }