Author:
bzerangue
Version:
1.0.1
Release Date:
21 Feb 2011
Category:
Third-Party Integration

Browse

Description

Have you wanted to added a Facebook Like Button to your site? Here's a basic utility allowing you to do that easily.

Basic usage:

Import this utility to your existing xslt template and then call the template like so...

<xsl:call-template name="facebook-like">
   <xsl:with-param name="url-to-like" select="'http://site.com'"/>
 </xsl:call-template>

The "url-to-like" parameter is required, other than that you can customize your output with the other optional parameters. The Facebook Like Reference will explain those optional parameters are.

View this gist.

IMPORTANT NOTE: (from mqchen) Just a tip; I think you need to add two namespaces in the html tag for it to work in some IE versions. xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"

XSLT

View Raw
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fb="http://www.facebook.com/2008/fbml"
    xmlns:og="http://ogp.me/ns#"
    exclude-result-prefixes="fb og"
    version="1.0">

    <!-- 
        Name: Facebook Like Utility
        Version: 1.0.1
        Author: Brian Zerangue <brian.zerangue@gmail.com>
        
        How to use
        - Import this utility in your page, <xsl:import href="path/facebook-like-utility.xsl"/>
        - Call the template name="facebook-like" like so...
        - Required Parameter is url-to-like, all the other parameters are optional
        
        <xsl:call-template name="facebook-like">
          <xsl:with-param name="url-to-like" select="'http://site.com'"/>
        </xsl:call-template>
    -->
        
    <xsl:template name="facebook-like">
        <xsl:param name="url-to-like"/><!-- Required -->
        <xsl:param name="layout" select="'standard'"/>
        <xsl:param name="show_faces" select="'false'"/>
        <xsl:param name="font" select="'lucida grande'"/>
        <xsl:param name="width" select="450"/>
        <xsl:param name="action" select="'like'"/>
        <xsl:param name="colorscheme" select="'light'"/>
        <xsl:param name="send" select="'true'"/>
        <script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>
        <xsl:if test="$layout='standard'">
            <fb:like href="{$url-to-like}" show_faces="{$show_faces}" width="{$width}" font="{$font}" send="{$send}">
                <xsl:if test="not($action='like')">
                    <xsl:attribute name="action">
                        <xsl:value-of select="$action"/>
                    </xsl:attribute>
                </xsl:if>
                <xsl:if test="not($colorscheme='light')">
                    <xsl:attribute name="colorscheme">
                        <xsl:value-of select="$colorscheme"/>
                    </xsl:attribute>
                </xsl:if>
                <xsl:comment> Facebook Like </xsl:comment>
            </fb:like>  
        </xsl:if>
        <xsl:if test="$layout='button_count'">
            <fb:like href="{$url-to-like}" show_faces="{$show_faces}" width="{$width}" font="{$font}" send="{$send}">
                <xsl:attribute name="layout">
                    <xsl:value-of select="$layout"/>
                </xsl:attribute>
                <xsl:if test="not($action='like')">
                    <xsl:attribute name="action">
                        <xsl:value-of select="$action"/>
                    </xsl:attribute>
                </xsl:if>
                <xsl:if test="not($colorscheme='light')">
                    <xsl:attribute name="colorscheme">
                        <xsl:value-of select="$colorscheme"/>
                    </xsl:attribute>
                </xsl:if>
                <xsl:comment> Facebook Like </xsl:comment>
            </fb:like> 
        </xsl:if>
        <xsl:if test="$layout='box_count'">
            <fb:like href="{$url-to-like}" show_faces="{$show_faces}" width="{$width}" font="{$font}" send="{$send}">
                <xsl:attribute name="layout">
                    <xsl:value-of select="$layout"/>
                </xsl:attribute>
                <xsl:if test="not($action='like')">
                    <xsl:attribute name="action">
                        <xsl:value-of select="$action"/>
                    </xsl:attribute>
                </xsl:if>
                <xsl:if test="not($colorscheme='light')">
                    <xsl:attribute name="colorscheme">
                        <xsl:value-of select="$colorscheme"/>
                    </xsl:attribute>
                </xsl:if>
                <xsl:comment> Facebook Like </xsl:comment>
            </fb:like> 
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>

Discuss this XSLT Utility

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details