Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Zoltan Torteli 13 posts 34 karma points
    Feb 01, 2012 @ 04:41
    Zoltan Torteli
    0

    How to add post, by not authenticated visitor?

    Hi!

    First of all, I would like to thank for this great stuff!

    I ma usind Umbraco 4.7.1 with uBlogsy.

    I am facing a problem, where the site is in intranet, and the need is to add blogposts without logging in.

    Like having the comment form, but adding posts with it.

     

    All help / idea is apreciated!

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Feb 01, 2012 @ 16:25
    Anthony Dang
    0

    You could try using windows live writer if that's an option.

     

    Otherwise you'll have to make a form and use the document api http://our.umbraco.org/wiki/reference/api-cheatsheet

     

  • Zoltan Torteli 13 posts 34 karma points
    Feb 02, 2012 @ 17:52
    Zoltan Torteli
    0

    Hi Anthony!

    Problem solved, in fact I have been creating a form, and so on... I am happy to post here the solution, if you don't mind. 

     

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Feb 02, 2012 @ 18:51
    Anthony Dang
    0

    Go for it.

  • Zoltan Torteli 13 posts 34 karma points
    Feb 03, 2012 @ 06:41
    Zoltan Torteli
    0

    So, what I did, copied the Content.aspx, and changed it to be able to add a blogpost. I am sure, that there is a better solution. Howerver it does work. All suggestions are wellcome!

    As follows.

    AdduBlogsyPost.ascx file source

    <%@ControlLanguage="C#"AutoEventWireup="true"CodeBehind="AdduBlogsyPost.ascx.cs"Inherits="uBlogsyAddPost.AdduBlogsyPost"%>

     

    <divclass="uBlogsy_comment_form">

        <asp:MultiViewID="mv"runat="server"ActiveViewIndex="0">

            <asp:ViewID="vwForm"runat="server">

                <divclass="uBlogsy_row">

                    <labelfor="txtName"id="txtNameLabel"class="postlabel">

                        Navn/Name<asp:RequiredFieldValidatorID="RequiredFieldValidator3"runat="server"ControlToValidate="txtName"

                            Display="Dynamic">*</asp:RequiredFieldValidator>

                    </label>

                    <asp:TextBoxID="txtName"runat="server"></asp:TextBox>

                </div>

                <divclass="uBlogsy_row tall">

                    <labelfor="txtMessage"id="txtMessageLabel"class="postlabel">

                        Kommentar/comment<asp:RequiredFieldValidatorID="RequiredFieldValidator1"runat="server"ControlToValidate="txtMessage"

                            Display="Dynamic">*</asp:RequiredFieldValidator>

                    </label>

                    <asp:TextBoxID="txtMessage"runat="server"TextMode="MultiLine"></asp:TextBox>

                </div>

                <asp:ButtonID="btnSubmit"runat="server"Text="Submit"OnClick="btnSubmit_Click"/>

            </asp:View>

            <asp:ViewID="vwSuccess"runat="server">

                Tak for dit indlæg.

            </asp:View>

        </asp:MultiView>

    </div>

     

    -----------------------------------------------------------------------

    AdduBlogsyPost.ascx.cs source

     

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Web;

    using System.Web.UI;

    using System.Web.UI.WebControls;

    using System.Collections;

    using umbraco.presentation.templateControls;

    using umbraco.MacroEngines;

    using uHelpsy.Core;

    using umbraco.NodeFactory;

     

    using uBlogsy.BusinessLogic;

    using umbraco.cms.businesslogic.web;

     

     

    namespace uBlogsyAddPost

    {

        publicpartialclassAdduBlogsyPost : System.Web.UI.UserControl

        {

            private string m_NodeTypeAlias;

            private int m_PageId;

     

            private int m_BlogPageID;

     

            public string blogPageId

            {

                get 

                {

                    return m_BlogPageID.ToString();

                }

     

                set

                {

                    m_BlogPageID = int.Parse(value);

                }

            }

     

            #region OnLoad

            protected override void OnLoad(EventArgs e)

            {

                base.OnLoad(e);

     

                Item item = new Item();

                m_PageId = int.Parse(item.PageElements["pageID"].ToString());

     

                // check what type of page this is

                m_NodeTypeAlias = item.PageElements["nodeTypeAlias"].ToString();

     

                // was redirected to current page to ensure razor macro is refreshed

                if (!string.IsNullOrEmpty(Request.QueryString["success"]) && Request.QueryString["success"] == "true")

                {

                    mv.ActiveViewIndex = 1;

                }

            }

            #endregion

     

            #region btnSubmit_Click

     

            protected void btnSubmit_Click(object sender, EventArgs e)

            {

                CreatePost();

     

                // redirect to current page to ensure razor macro is refreshed

                Response.Redirect(Request.Url.AbsolutePath.ToString() + "?success=true");

            }

            #endregion

     

     

            #region Post methods

     

            #region CreatePost

            ///<summary>

            /// Creates an umbraco node under the current page

            ///</summary>

            private void CreatePost()

            {

                DateTime today = DateTime.Now;

     

                int year = today.Year;

                int month = today.Month;

                int day = today.Day;

     

                Document yearFolder = null;

                Document monthFolder = null;

                Document dayFolder = null;

     

                // blogNode id

                Document blogFolder = new Document(m_BlogPageID); 

     

                // year node

                yearFolder = GetYearFolder(blogFolder, today);

     

                // month node

                monthFolder = GetMonthFolder(yearFolder, today);

     

                // day node

                dayFolder = GetDayFolder(monthFolder, today);

     

                

                string name = Server.HtmlEncode(txtName.Text);

     

                Dictionary<string, object> postDic = GetDefaultDictionary(); 

                    postDic["uBlogsyContentTitle"] = "eksampel";

                    postDic["uBlogsyContentSummary"] = Server.HtmlEncode(txtMessage.Text);

                    postDic["uBlogsyContentBody"] = Server.HtmlEncode(txtMessage.Text);

                    postDic["uBlogsyPostDate"] = DateTime.Now;

                    postDic["uBlogsyPostDisableComments"] = 0;

                    postDic["uBlogsyPostAuthor"] = Server.HtmlEncode(txtName.Text);

                    postDic["uBlogsySeoDescription"] = "";

     

                Document post = UmbracoAPIHelper.CreateContentNode("ekspempel", "uBlogsyPost", postDic, dayFolder.Id/*dayFolder.Id*/, true);

                umbraco.library.UpdateDocumentCache(post.Id); 

                //post.Save();

     

                // create the Comments folder too!

                Document commentsFolder = CreateCommentsFolder(post.Id);

                umbraco.library.UpdateDocumentCache(commentsFolder.Id);

            }

     

      

            #region CreateCommentsFolder

            ///<summary>

            /// Creates a uBlogsyPost Document 

            ///</summary>

            ///<param name="item"></param>

            ///<param name="parentId"></param>

            ///<returns></returns>

            /// 

            private Document CreateCommentsFolder(int parentId)

            {

                Dictionary<string, object> commentFolderDic = GetDefaultDictionary();

                        commentFolderDic["uBlogsyContentTitle"] = "Comments";

                        commentFolderDic["uBlogsyContentBody"] = "";

     

                return UmbracoAPIHelper.CreateContentNode("Comments", "uBlogsyContainerComment", commentFolderDic, parentId, true);

            }

     

            #endregion

     

            #endregion

            

            #endregion

     

     

            public static Dictionary<string, object> GetDefaultDictionary()

            {

                Dictionary<string, object> dictionary = new Dictionary<string, object>() 

                        { 

                            { "uBlogsyContentTitle", string.Empty }, 

                            { "uBlogsyContentBody", string.Empty },

                            { "uBlogsySeoKeywords", string.Empty},

                            { "uBlogsySeoDescription", string.Empty},

                            { "umbracoNaviHide", 0},

                            { "umbracoRedirect", string.Empty},

                            { "umbracoUrlName", string.Empty},

                            { "umbracoInternalRedirectId", string.Empty},

                            { "umbracoUrlAlias", string.Empty}

                        };

                return dictionary;

            }

     

     

            #region GetYearFolder

            ///<summary>

            /// Creates a uBlogsyFolderYear document

            ///</summary>

            ///<param name="blogFolderId"></param>

            ///<param name="year"></param>

            ///<returns></returns>

            private Document GetYearFolder(Document blogFolder, DateTime today)

            {

                string yearName = today.ToString("yyyy");

     

                foreach (var child in blogFolder.Children)

                {

                    if (child.ContentType.Alias == "uBlogsyFolderYear")

                    {

                        if (child.Text.Contains(yearName))

                        {

                            return child;

                        }

                    }

                }

     

                Dictionary<string, object> yearDic = GetDefaultDictionary();

                yearDic["uBlogsyContentTitle"] = yearName;

                yearDic["uBlogsyContentBody"] = "";

     

                return UmbracoAPIHelper.CreateContentNode(yearName, "uBlogsyFolderYear", yearDic, blogFolder.Id, true);

            }

     

            #endregion

     

            #region GetMonthFolder

            ///<summary>

            /// Creates a month folder

            ///</summary>

            ///<param name="item"></param>

            ///<param name="parentId"></param>

            ///<returns></returns>

            private Document GetMonthFolder(Document yearFolder, DateTime today)

            {

                string monthName = today.ToString("MMMM");

     

                foreach (var child in yearFolder.Children)

                {

                    if (child.ContentType.Alias == "uBlogsyFolderMonth")

                    {

                        if (child.Text.Trim().ToLower().Contains(monthName.ToLower()))

                        {

                            return child;

                        }

                    }

                }

     

                Dictionary<string, object> monthDic = GetDefaultDictionary();

                monthDic["uBlogsyContentTitle"] = monthName;

                monthDic["uBlogsyContentBody"] = "";

     

                return UmbracoAPIHelper.CreateContentNode(monthName, "uBlogsyFolderMonth", monthDic, yearFolder.Id, true);

            }

     

            #endregion

     

            #region GetDayFolder

            ///<summary>

            /// Creates a month folder

            ///</summary>

            ///<param name="item"></param>

            ///<param name="parentId"></param>

            ///<returns></returns>

            private Document GetDayFolder(Document monthFolder, DateTime today)

            {

                string dayName = today.ToString("dd");

     

                foreach (var child in monthFolder.Children)

                {

                    if (child.ContentType.Alias == "uBlogsyFolderDay")

                    {

                        if (child.Text.Contains(dayName))

                        {

                            return child;

                        }

                    }

                }

     

                Dictionary<string, object> monthDic = GetDefaultDictionary();

                monthDic["uBlogsyContentTitle"] = dayName;

                monthDic["uBlogsyContentBody"] = "";

     

                return UmbracoAPIHelper.CreateContentNode(dayName, "uBlogsyFolderDay", monthDic, monthFolder.Id, true);

            }

     

            #endregion

        }

    }

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Feb 03, 2012 @ 13:35
    Anthony Dang
    0

    Yep. That's more or less the way to do it.

     

  • Zoltan Torteli 13 posts 34 karma points
    Feb 03, 2012 @ 13:47
    Zoltan Torteli
    0

    I think I have forgotten to publish the year, month, day nodes.... so that could be fixed...

     

Please Sign in or register to post replies

Write your reply to:

Draft