Copied to clipboard

Flag this post as spam?

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


  • BarneyHall 141 posts 210 karma points
    Nov 13, 2009 @ 18:41
    BarneyHall
    0

    share this - social bookmarking package?

    Hello,

    I wanted to add the ability to share pages across various bookmarking sites - a bit like the AddThis service but without relying on them.

    I found this guy's post which is very helpful but being a bit wet behind the ears I'm struggling to get this working with Umbraco.
    http://mark.koli.ch/2009/02/howto-make-your-own-addthis-social-bookmarking-sharing-widget-thing.html

    Essentially the problem is with passing the URL of the submitted page.

    Can anyone offer any advice? Better still, does anyone have a working solution?

    Thanks,
    Barney

  • dandrayne 1138 posts 2262 karma points
    Nov 13, 2009 @ 19:36
    dandrayne
    1

    This will get the full path to the current page in xslt

    <xsl:text>http://</xsl:text>;
    <xsl:value-of select="umbraco.library:RequestServerVariables('SERVER_NAME')"/>
    <xsl:value-of select="umbraco.library:NiceUrl($currentPage/@id)"/>

    Then it's just  a case of passing this.  You could wrap all the above into a variable and then submit that

    <xsl:variable name="thisPage">
    <xsl:text>http://</xsl:text>;
    <xsl:value-of select="umbraco.library:RequestServerVariables('SERVER_NAME')"/>
    <xsl:value-of select="umbraco.library:NiceUrl($currentPage/@id)"/>
    </xsl:variable>

    Then submit it with

    http://add.toyoursocialthing.com/?add=<xsl:value-of select="$thisPage" />

    Or something like that!

    Dan

  • BarneyHall 141 posts 210 karma points
    Nov 18, 2009 @ 19:19
    BarneyHall
    0

    Hi Dan, thanks for your input on this.

    I'm sorry but I need a bit more hand holding here than your usual Umbraco peep.

    I just wanted to confirm that it sounds like your saying that we don't need to worry about the Javascript from the Mark S Kolich post above, but instead we can do it on each a href with your XSLT?

    Cheers ears,
    Barney

  • dandrayne 1138 posts 2262 karma points
    Nov 19, 2009 @ 15:51
    dandrayne
    0

    Hi Barney

    You could indeed do it all with just xslt and ignore the javascript such as "self.location.href" as used in the linked post, so in your list of social sites you'd have something like

    <?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"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">

    <xsl:variable name="thisPage">
    <xsl:text>http://</xsl:text>;
    <xsl:value-of select="umbraco.library:RequestServerVariables('SERVER_NAME')"/>
    <xsl:value-of select="umbraco.library:NiceUrl($currentPage/@id)"/>
    </xsl:variable>
    <xsl:variable name="thisPageTitle">
    <xsl:value-of select="$currentPage/@nodeName" />
    <!-- or whatever other property you want to use for page title -->
    </xsl:variable>

    <p class="shareitem stumbleupon">
    <a href="http://www.stumbleupon.com/submit?url={$thisPage}&title={$thisPageTitle}">
    <xsl:text>Stumble Upon</xsl:text>
    </a>
    </p>


    </xsl:template>

    </xsl:stylesheet>

     

    Looking at the linked post, I don't like (and don't see why he has done this) adding non-standard attributes to the A tag but something like the above should also work and doesn't rely on javascript.

    Hope this helps,
    Dan

  • Peter Duncanson 430 posts 1360 karma points c-trib
    Nov 20, 2009 @ 16:04
    Peter Duncanson
    0

    A nice tip is that for Facebook (and I believe others are adopting it) you can include an image url in your head of your doc and Facebook will use that as the default image for your page when you link to it

    <link rel="image_src" href="http://example.com/mypic.jpg" />

    You could include that in the master template?

  • BarneyHall 141 posts 210 karma points
    Nov 28, 2009 @ 20:14
    BarneyHall
    0

    @Peter - nice one for that, will definitely do that as I can imagine my client loving the fact we can pass their logo over!

    @Dan -

    Thank you, you've already been a huge help, and really do appreciate your assistance here.

    I've done as you've suggested above, but with the example you've given (i.e. Stumble Upon) the XSLT is tripping over having "&title" in the achor href. I know this has come from the AddThis list and yes I would prefer to keep it as passing the page title is a nice touch.

    I'm just wondering if maybe the href is too long for XSLT and maybe I need to break it down and build the string through using "xsl:attribute"?

    What do you think?

    Cheers,
    Barney

     

  • Peter Duncanson 430 posts 1360 karma points c-trib
    Nov 28, 2009 @ 21:31
    Peter Duncanson
    0

    Daft question but is it complaining about undefined entities? The & should be encoded as &amp; is that too obvious?

    XSL should not have any problems with the length of the href, it should just get on with it. Try something like:

    <a href="http://www.stumbleupon.com/submit?url={$thisPage}&amp;title={$thisPageTitle}">
         
    <xsl:text>Stumble Upon</xsl:text>
     
    </a>
  • BarneyHall 141 posts 210 karma points
    Nov 29, 2009 @ 19:22
    BarneyHall
    0

    Bingo. You rock :)

  • Peter Duncanson 430 posts 1360 karma points c-trib
    Nov 29, 2009 @ 22:33
    Peter Duncanson
    0

    Thanks, late night coding, always a killer ;)

Please Sign in or register to post replies

Write your reply to:

Draft