Viewing 1 post (of 1 total)
  • Author
    Posts
  • jooservices Friend
    #168701

    I’m still working w/ JA Plugin facebook Share / Like.
    This’s class is a part of it ( by use class we could make code more clean and easier for maintenance )

    In this class you can use facebook by provide params into class and use render function.

    Like this:


    $this->fbButton = new JOOFfacebookButton ('iframe');
    /**
    * Method to render button into article
    */
    function render($position, &$article, &$params, $limitstart) {
    return $this->fbButton->render();
    }

    function onAfterRender () {
    $facebook = new JOOFfacebookButton ();
    $facebook->setXFBML();
    }

    Easier huh ?
    Yo.
    Beside that in this class i’ve also working with Open Graph Tags. Facebook language based on current Joomla language ( yo i’ll update to use with JoomFish 😀 )

    Please let’s me know if you have any comments / ideas
    Thank you
    Viet Vu


    <?php
    /**
    * @name JOOframework
    * @version 1.0.0 Aug 26 2011
    * @package Joomla plugin
    * @subpackage System
    * @author Viet Vu
    * @copyright (C) 2009 - 2011 by JOOservices Ltd Company - All rights reserved!
    * @license GNU/GPL, see LICENSE.php
    * @link http://jooservices.com
    * @uses
    * This class use for render Google +1 Button
    */

    /**
    * OWNER %%LICENSED_TO%%
    */

    // Check to ensure this file is included in Joomla!
    defined ( '_JEXEC' ) or die ( 'Restricted access' );
    ?>
    <?php

    class JOOFfacebookButton {

    public $buttonParams = array ();
    public $openGraphParams = array ();
    public $params;

    private $document;

    public function __construct($type = 'html5') {
    $this->params ['type'] = $type;

    $this->document = & JFactory::getDocument ();
    /* the URL to like. The XFBML version defaults to the current page. */
    $this->buttonParams ['href'] = JURI::getInstance ()->toString (); /* by default we use current url page */

    /* send: specifies whether to include a Send button with the Like button */
    /* str: true / false */
    $this->buttonParams ['send'] = 'false';

    /* layout */
    /* str: standard / button_count / box_count */
    $this->buttonParams ['layout'] = 'standard';

    /* show_faces: specifies whether to display profile photos below the button (standard layout only) */
    /* str: true / false */
    $this->buttonParams ['show_faces'] = 'true';

    /* width */
    $this->buttonParams ['width'] = 225;

    /* action: the verb to display on the button. Options: 'like', 'recommend' */
    $this->buttonParams ['action'] = 'like';

    /* font: the font to display in the button. Options: 'arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana' */
    $this->buttonParams ['font'] = 'verdana';

    /* colorscheme */
    /* str: dark / light */
    $this->buttonParams ['colorscheme'] = 'light';

    /*
    ref - a label for tracking referrals; must be less than 50 characters and can contain alphanumeric characters and some punctuation (currently +/=-.:_). The ref attribute causes two parameters to be added to the referrer URL when a user clicks a link from a stream story about a Like action:
    fb_ref - the ref parameter
    fb_source - the stream type ('home', 'profile', 'search', 'other') in which the click occurred and the story type ('oneline' or 'multiline'), concatenated with an underscore.
    */

    $this->openGraphParams ['title'] = $this->document->title;
    $this->openGraphParams ['type'] = 'website';
    $this->openGraphParams ['url'] = JURI::getInstance ()->toString (); /* by default we use current url page */
    $this->openGraphParams ['image'] = '';
    $this->openGraphParams ['sitename'] = $this->document->title;
    $this->openGraphParams ['admin'] = '100002155587121';

    }

    /**
    * Method to get attributes string
    */
    public function getAttribs() {
    $htmlAttribs = '';

    foreach ( $this->buttonParams as $key => $attrib ) {
    switch ($this->params ['type']) {
    case 'html5' :
    $htmlAttribs .= ' data-' . $key . '="' . $attrib . '"';
    break;
    case 'xfbml' :
    if ($key == 'send')
    $attrib = 'false';
    $htmlAttribs .= '&' . $key . '="' . $attrib . '"';
    default :
    $htmlAttribs .= ' ' . $key . '="' . $attrib . '"';
    break;
    }
    }
    return $htmlAttribs;
    }

    /**
    * Method execute facebook javascript
    * @todo Need update with Asynchronously
    * @todo We can use javascript for checking and include as dynamic
    */
    private function loadScript() {
    static $loaded;
    if (! isset ( $loaded )) {
    $fbFile = 'connect.facebook.net/' . str_replace ( '-', '_', JFactory::getLanguage ()->getTag () ) . '/all.js';
    switch ($this->params ['type']) {
    case 'html5' :
    $fbScript = '(function(d, s, id){
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) {return;}
    js = d.createElement(s); js.id = id;
    js.src = "//' . $fbFile . '#appId=100333823408874&xfbml=1";
    fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'))';
    break;
    case 'xfbml' :
    $fbScript = '(function(d, s, id){
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) {return;}
    js = d.createElement(s); js.id = id;
    js.src = "//' . $fbFile . '#appId=100333823408874&xfbml=1";
    fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'))';
    break;
    default :
    $fbScript = '';
    break;
    }

    if ($fbScript != '') {
    $doc = & JFactory::getDocument ();
    $doc->addScriptDeclaration ( $fbScript );
    }
    $loaded = true;
    }

    }

    /**
    * Method to set html with facebook XFBML standard
    */
    public function setXFBML() {
    if ($this->params ['type'] == 'xfbml') {
    $body = JResponse::getBody ();
    $regex = "/<html.*?xmlns:fb=".*?"[^>]*?>/i";
    if (! preg_match ( $regex, $body )) {
    $body = str_replace ( '<html', '<html xmlns:fb="http://www.facebook.com/2008/fbml"', $body );
    }
    JResponse::setBody ( $body );
    }
    }

    /**
    * Method to get fb with HTML5
    */
    private function getHTML5() {
    $html = '<div id="fb-root"></div>';
    $html .= '<div class="joo-fbLike"><div class="fb-like" ' . $this->getAttribs () . '></div></div>';
    return $html;
    }

    /**
    * Method to get fb with XFBML
    */
    private function getXFBML() {
    $html = '<div id="fb-root"></div>';
    $html .= '<div class="joo-fbLike"><fb:like ' . $this->getAttribs () . '></fb:like></div>';
    return $html;
    }

    /**
    * Method to get fb with IFRAME
    */
    private function getIframe() {
    $html = '<div class="joo-fbLike"><iframe src="//www.facebook.com/plugins/like.php?app_id=100333823408874' . $this->getAttribs () . '" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:' . $this->buttonParams ['width'] . 'px; height:90px;" allowTransparency="true"></iframe></div>';
    return $html;
    }

    /**
    * Complete method to render fb into page
    * @return string
    */
    public function render() {
    $this->loadScript ();
    switch ($this->params ['type']) {
    case 'html5' :
    $html = $this->getHTML5 ();
    break;
    case 'xfbml' :
    $html = $this->getXFBML ();
    break;
    case 'iframe' :
    $html = $this->getIframe ();
    break;
    default :
    $html = $this->getHTML5 (); /* by default we are using HTML5 */
    break;
    }
    return $html;
    }

    }
    ?>

Viewing 1 post (of 1 total)

This topic contains 1 reply, has 1 voice, and was last updated by  jooservices 13 years, 2 months ago.

We moved to new unified forum. Please post all new support queries in our New Forum