Copied to clipboard

Flag this post as spam?

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


  • curlybub 133 posts 107 karma points
    Feb 05, 2010 @ 02:51
    curlybub
    0

    Extending Blog 4 Umbraco

    Hi,

    We installed the blog 4 umbraco package, it is working as it should. But we need to put some security measures when it comes to posting comments on the blog entry. What we want to do is that when a user wants to comment on the blog post they should be logged in first and the name and email fields should be populated already with their name and email address (information is already available on the members area) after logging in.

    Can we do this without the source code? Do you have any idea where I can get the soure code of the blog 4 umbraco package?

    Do you have any idea on how to do this?

    Thank you.

     

    Regards,
    Harry

  • dandrayne 1138 posts 2262 karma points
    Feb 05, 2010 @ 14:15
    dandrayne
    0

    Hi Harry

    I haven't yet used the new blog4umbraco, but if the comment form is an xslt macro you can wrap the following function around it

    <xsl:if test="umbraco.library:IsLoggedOn()">

    <!-- Comment form -->
    <xsl:variable name="currentMember" select="umbraco.library:GetCurrentMember()" />

    </xsl:if>

    Also shown is getting the current member in xslt , and at http://our.umbraco.org/wiki/reference/umbracolibrary/getmember you'll see how to access member properties. 

    Dan

  • curlybub 133 posts 107 karma points
    Feb 06, 2010 @ 16:27
    curlybub
    0

    Hi,

    Thank you for your reply. I'm using the old blog for umbraco. I'll try your suggestion. Again. Thank you so much.

     

    Regards,
    Harry

  • curlybub 133 posts 107 karma points
    Feb 08, 2010 @ 08:16
    curlybub
    0

    Hi the old blog4umbraco package is using a user control for the comment form. Is there a way that I can check if the user is logged in before they can give a comment to the blog post?

    Thank you.

    Regards,
    Harry

  • dandrayne 1138 posts 2262 karma points
    Feb 08, 2010 @ 11:45
    dandrayne
    0

    For the c# code you'd need to find someone else, sorry!

    What you can do (and what I have done) is to create different templates for users who are and aren't logged in.  One template would contain the usercontrol that allows commenting and one wouldn't.  Like the following

    <xsl:variable name="loggedInTemplate" select="2387" />
    <xsl:variable name="loggedOutTemplate" select="2388" />
    <xsl:variable name="currentId" select="$currentPage/@id" />

    <xsl:choose>
    <xsl:when test="umbraco.library:IsLoggedOn()">
    <xsl:value-of select="umbraco.library:RenderTemplate($currentId,$loggedInTemplate)" disable-output-escaping="yes" />
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="umbraco.library:RenderTemplate($currentId,$loggedOutTemplate)" disable-output-escaping="yes" />
    </xsl:otherwise>
    </xsl:choose>
    </xsl:template>

    RenderTemplate takes a template ID and the ID of the current page as parameters and can easily be used to do what you are after.

    Dan

  • curlybub 133 posts 107 karma points
    Feb 08, 2010 @ 14:29
    curlybub
    0

    Wow! This xslt amazes me. However I cannot understand what this xslt does. Do you have a working sample that I can view online? I'm more on the designing part, I guess I need to have someone help me with this one. 

    Again, I'll give it a try. Can you explain further?

    Thank you.

    Regards,
    Harry

  • dandrayne 1138 posts 2262 karma points
    Feb 08, 2010 @ 15:30
    dandrayne
    0

    No problem,

    Ok in the above example I've got two "blog post" templates.  One of the templates includes a comment form and one has a message saying "You much be logged in to post comments".  Both of these templates are allowed on the blog post page, but the default (3rd) template contains only the above macro, which takes the IDs of the two optional templates (logged in/logged out) and renders the correct one based on whether or not the user is logged in.

    <!-- template ID for logged in users -->
    <xsl:variable
    name="loggedInTemplate" select="2387" />
    <!-- template for logged out template -->
    <xsl:variable name="loggedOutTemplate" select="2388" />
    <!-- current page ID -->
    <xsl:variable name="currentId" select="$currentPage/@id" />
    <!-- is user logged in? -->
           
    <xsl:choose>
                   
    <xsl:when test="umbraco.library:IsLoggedOn()">
                           
    <xsl:value-of select="umbraco.library:RenderTemplate($currentId,$loggedInTemplate)" disable-output-escaping="yes" />
                   
    </xsl:when>
                   
    <xsl:otherwise>
                           
    <xsl:value-of select="umbraco.library:RenderTemplate($currentId,$loggedOutTemplate)" disable-output-escaping="yes" />
                   
    </xsl:otherwise>
           
    </xsl:choose>
    </xsl:template>

    Dan

  • curlybub 133 posts 107 karma points
    Feb 09, 2010 @ 02:33
    curlybub
    0

    Thanks again.

    Lets say I have created a template already and got their ID numbers on the properties tab.
    Where do I place this xslt that you've created? I checked the templates for the old blog4umbraco and under the blogPost template is the Leave a Comment link.

    Here is the code for the blogPost template:
    [code]<%@ Master Language="C#" MasterPageFile="/masterpages/BlogMaster.master" AutoEventWireup="true" %>
    <asp:Content ContentPlaceHolderID="head" runat="server">
    <style type="text/css" media="screen">

     #page{ background: url("/images/kubrickbgwide.jpg") repeat-y top; border: none; }

    </style>
    </asp:Content>

    <asp:Content ContentPlaceHolderID="body" runat="server">
    <div id="content" class="widecolumn">
     <div class="post">
    <h2><umbraco:Item field="pageName" runat="server"></umbraco:Item></h2>
    <umbraco:Item field="createDate" formatAsDate="true" runat="server"></umbraco:Item> by <umbraco:Item field="writerName" runat="server"></umbraco:Item><br/>

    <div class="entrytext">
    <umbraco:Item field="bodyText" runat="server"></umbraco:Item>
    </div>

    </div>

    <umbraco:Macro Alias="BlogPostListComments" runat="server"></umbraco:Macro>

    <h3 id="respond">Leave comment:</h3>
    <umbraco:Macro Alias="frmBlogComment" runat="server"></umbraco:Macro>

    </div>
    </asp:Content>[/code]

    I assume that the xslt that you gave me should be triggered after clicking the Leave a comment link.

    Whoa! Im going in circles. Hehe. 

  • curlybub 133 posts 107 karma points
    Feb 09, 2010 @ 02:34
    curlybub
    0

    Thanks again.

    Lets say I have created a template already and got their ID numbers on the properties tab.
    Where do I place this xslt that you've created? I checked the templates for the old blog4umbraco and under the blogPost template is the Leave a Comment link.

    Here is the code for the blogPost template:
    [code]
    <%@ Master Language="C#" MasterPageFile="/masterpages/BlogMaster.master" AutoEventWireup="true" %>
    <asp:Content ContentPlaceHolderID="head" runat="server">
    <style type="text/css" media="screen">

     #page{ background: url("/images/kubrickbgwide.jpg") repeat-y top; border: none; }

    </style>
    </asp:Content>

    <asp:Content ContentPlaceHolderID="body" runat="server">
    <div id="content" class="widecolumn">
     <div class="post">
    <h2><umbraco:Item field="pageName" runat="server"></umbraco:Item></h2>
    <umbraco:Item field="createDate" formatAsDate="true" runat="server"></umbraco:Item> by <umbraco:Item field="writerName" runat="server"></umbraco:Item><br/>

    <div class="entrytext">
    <umbraco:Item field="bodyText" runat="server"></umbraco:Item>
    </div>

    </div>

    <umbraco:Macro Alias="BlogPostListComments" runat="server"></umbraco:Macro>

    <h3 id="respond">Leave comment:</h3>
    <umbraco:Macro Alias="frmBlogComment" runat="server"></umbraco:Macro>

    </div>
    </asp:Content>
    [/code]

    I assume that the xslt that you gave me should be triggered after clicking the Leave a comment link.

    Whoa! Im going in circles. Hehe. 

  • curlybub 133 posts 107 karma points
    Feb 09, 2010 @ 02:35
    curlybub
    0

    Sorry for the double post, I cant get the code window to output the same as yours. Hehe.

  • curlybub 133 posts 107 karma points
    Feb 09, 2010 @ 02:42
    curlybub
    0
     <%@ Master Language="C#" MasterPageFile="/masterpages/BlogMaster.master" AutoEventWireup="true" %>
    <asp:Content ContentPlaceHolderID="head" runat="server">
    <style type="text/css" media="screen">
    #page{ background: url("/images/kubrickbgwide.jpg") repeat-y top; border: none; }
    </style>
    </asp:Content>



    <asp:Content ContentPlaceHolderID="body" runat="server">
    <div id="content" class="widecolumn">
     <div class="post">
    <h2><umbraco:Item field="pageName" runat="server"></umbraco:Item></h2>
    <umbraco:Item field="createDate" formatAsDate="true" runat="server"></umbraco:Item> by <umbraco:Item field="writerName" runat="server"></umbraco:Item><br/>
    <div class="entrytext">
    <umbraco:Item field="bodyText" runat="server"></umbraco:Item>
    </div>
    </div>
    <umbraco:Macro Alias="BlogPostListComments" runat="server"></umbraco:Macro>
    <h3 id="respond">Leave comment:</h3>
    <umbraco:Macro Alias="frmBlogComment" runat="server"></umbraco:Macro>
    </div>
    </asp:Content>

    There I think I got to past the code correctly. :D

  • dandrayne 1138 posts 2262 karma points
    Feb 09, 2010 @ 10:32
    dandrayne
    0

    Ok, so I'd duplicate the blogpost template and remove the

    <umbraco:Macro Alias="frmBlogComment" runat="server"></umbraco:Macro>

    line from the copy of the template.  You can replace it with a "you must be logged in" message or something.

    Then I'd use the code above in a third template which will be the template actually used for the blogpost document type.  Use this as your default blogpost template and all it does is decide whether or not your user is logged in, then renders the correct template in it's place.  The third template is just a placeholder that chooses whether or not the user sees the template with blog comments or not.

    Is this clearer?

    Dan

  • curlybub 133 posts 107 karma points
    Feb 09, 2010 @ 16:36
    curlybub
    0

    Great! Thanks. I'll post again here if I have other questions. Do you have any links where I can learn great xslt? :D This is simply amazing.

  • dandrayne 1138 posts 2262 karma points
    Feb 09, 2010 @ 16:50
    dandrayne
    0

    Glad I could help. 

    http://umbraco.org/documentation/books/xslt-basics is a good start for the basics of xslt in umbraco, and installing something like (plug!) http://our.umbraco.org/projects/business-website-starter-pack or http://our.umbraco.org/projects/creative-website-starter-(cws) and looking through the sources will probably be a great help.

    Dan

  • curlybub 133 posts 107 karma points
    Mar 01, 2010 @ 06:26
    curlybub
    0

    Hi dandrayne,

    I'm getting an error when I try to create a XSLT macro for the code that you provided. Here is the whole XSLT that I did.

     

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
     version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:msxml="urn:schemas-microsoft-com:xslt"
     xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:MailEngine="urn:MailEngine" xmlns:pdcalendar="urn:pdcalendar" xmlns:Designit.VideoEmbed="urn:Designit.VideoEmbed" xmlns:tagsLib="urn:tagsLib" xmlns:BlogLibrary="urn:BlogLibrary"
     exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets MailEngine pdcalendar Designit.VideoEmbed tagsLib BlogLibrary ">

    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage"/>
    <xsl:template match="/">
    <!-- template ID for logged in users -->
    <xsl:variable name="loggedInTemplate" select="2387" />
    <!-- template for logged out template -->
    <xsl:variable name="loggedOutTemplate" select="2388" />
    <!-- current page ID -->
    <xsl:variable name="currentId" select="$currentPage/@id" />
    <!-- is user logged in? -->        
    <xsl:choose>               
     <xsl:when test="umbraco.library:IsLoggedOn()">                       
      <xsl:value-of select="umbraco.library:RenderTemplate($currentId,$loggedInTemplate)" disable-output-escaping="yes" />               
     </xsl:when>               
     <xsl:otherwise>                       
      <xsl:value-of select="umbraco.library:RenderTemplate($currentId,$loggedOutTemplate)" disable-output-escaping="yes" />               
     </xsl:otherwise>       
    </xsl:choose>
    </xsl:template>
    </xsl:stylesheet>

     

    Please help me with this one.

    Thank you.

     

    Regards,
    Harry

  • curlybub 133 posts 107 karma points
    Mar 01, 2010 @ 06:33
    curlybub
    0

    I thought this was going to be easy. Hehehe. Another question, where do I get the template ID? I still dont get it. Maybe it would be better to try this one first on a local site.

  • curlybub 133 posts 107 karma points
    Mar 02, 2010 @ 10:49
    curlybub
    0

    do i need to edit the default document type of the blog4umbraco package and include the 2 additional templates for the blogpost?

    dandrayne please enlighten me.

    Thank you.

  • curlybub 133 posts 107 karma points
    Mar 09, 2010 @ 09:59
    curlybub
    0

    Hi, 

    I was able to make the logging detection work. The problem that I'm having now is with the template. Here is a link of what is rendered when a logged in user tries to post a comment.

    http://i59.photbucket.com/albums/g294/Curlybub26/blogError.jpg and when I click on the submit button to check if it posts the comment it gives me an error as well. The state information is invalid for this page and might be corrupted. I also tried to check the processed html code, as i've noticed it renders 2 forms. The extra form is because it doesn't allow me to save the loggedIn template that has the formBlogPost user control without encapsulating it on  a form. I think this is just a template issue. 

    Hope you can help we with this one. If you have a working sample that I can view online and study, that would be a great help. 

    Thank you.

    Regards,
    Harry

  • curlybub 133 posts 107 karma points
    Mar 09, 2010 @ 10:01
    curlybub
    0

    Ooopppss! Sorry the link doesn't work. Try this.

  • dandrayne 1138 posts 2262 karma points
    Mar 09, 2010 @ 13:47
    dandrayne
    0

    Hi Curlybub

    An example using this (and with comments working) is online at http://www.st-georges.edin.sch.uk/secondary/subjects/geography/geography-blogs/2009/12/3/expedition-2009-blog#comments

    I've never seen the corrupted viewstate error before, so perhaps a trip to google is in order there

    (ps sorry for missing your previous posts here) - you can get the template id by hovering over the link to edit that template in the settings section and checking the id in the querystring.

  • curlybub 133 posts 107 karma points
    Mar 09, 2010 @ 23:11
    curlybub
    0

    Hi Dandrayne,

    I was able to find out why the viewstate error occurs, it is because I have two forms. The problem is if I remove the form tag on the template that has the blog comment form it will give me an error. I'm pretty sure that this is just a template issue. Try to look at this. Im not loading the templates right. Here is what my templates for the blogforumbraco looks like. 

    Template for the default blog post

    <%@ Master Language="C#" MasterPageFile="/masterpages/BlogMaster.master" AutoEventWireup="true" %>
    
    <asp:Content ContentPlaceHolderID="head" runat="server">
    <style type="text/css" media="screen">
    #page{ background: url("/images/kubrickbgwide.jpg") repeat-y top; border: none; }
    </style>
    </asp:Content>
    
    <asp:Content ContentPlaceHolderID="body" runat="server">
    <div id="content" class="widecolumn"> 
    <div class="post"><h2><umbraco:Item field="pageName" runat="server"></umbraco:Item></h2>
    <umbraco:Item field="createDate" formatAsDate="true" runat="server"></umbraco:Item> by <umbraco:Item field="writerName" runat="server"></umbraco:Item>
    
    <br/>
    <div class="entrytext"><umbraco:Item field="bodyText" runat="server"></umbraco:Item>
    </div>
    </div>
    <umbraco:Macro Alias="BlogPostListComments" runat="server"></umbraco:Macro>
    
    <h3 id="respond">Leave Comment</h3>
    
    <umbraco:Macro Alias="BlogLoginDetect" runat="server"></umbraco:Macro> 
    
    </div>
    </asp:Content>

    Template for the blog post if user is logged in:

    <%@ Master Language="C#" MasterPageFile="/masterpages/BlogMaster.master" AutoEventWireup="true" %>
    
    <asp:Content ContentPlaceHolderID="head" runat="server">
    <style type="text/css" media="screen">
    #page{ background: url("/images/kubrickbgwide.jpg") repeat-y top; border: none; }
    </style>
    </asp:Content>
    
    <asp:Content ContentPlaceHolderID="body" runat="server">
    <div id="content" class="widecolumn"> 
    <div class="post"><h2><umbraco:Item field="pageName" runat="server"></umbraco:Item></h2>
    <umbraco:Item field="createDate" formatAsDate="true" runat="server"></umbraco:Item> by <umbraco:Item field="writerName" runat="server"></umbraco:Item>
    
    <br/>
    <div class="entrytext"><umbraco:Item field="bodyText" runat="server"></umbraco:Item>
    </div>
    </div>
    <umbraco:Macro Alias="BlogPostListComments" runat="server"></umbraco:Macro>
    
    <h3 id="respond">Leave Comment</h3>
    
    <umbraco:Macro Alias="frmBlogComment" runat="server"></umbraco:Macro>
    
    
    </div>
    </asp:Content>

    But when I try to post a comment it looks like this.  :(( 

    Thank you.

    Regards,
    Harry

  • curlybub 133 posts 107 karma points
    Mar 10, 2010 @ 02:22
    curlybub
    0

    Hi!

    I got it working. I just used the default master page for the original blog post template. :D

    Thank you so much Dandrayne!

    Regards,
    Harry

  • dandrayne 1138 posts 2262 karma points
    Mar 10, 2010 @ 12:10
    dandrayne
    0

    Phew, glad you got it sorted Harry!  That was a mission ;-)

    Good luck,
    Dan

  • curlybub 133 posts 107 karma points
    Mar 11, 2010 @ 02:43
    curlybub
    0

    Hahahaha! :D

    Again, thank you so much!

Please Sign in or register to post replies

Write your reply to:

Draft