Wednesday, February 27, 2013

Facebook Activity Feed Using Php

Facebook Activity Feed plugin shows users what their friends are doing on your site through likes and comments.

Step for Facebook Update State :

1) Create Facebook class file :( Facebook_plugins_class.php ) 

in this add application id and language code and set facebook sdk on and then create one function
get_activity_feed() and apply its parameter.

class Facebook_plugins_class
{
    var $app_id = '115461585200271';
    var $lang = 'en_US'; //en_US, fr_FR, es_LA, ko_KR, ja_JP, de_DE
    var $fb_sdk = '1';
   
    function Facebook_plugins_class($criteria=array()) {
        static $witness;
        if($criteria['app_id']!='') $this->app_id = $criteria['app_id'];
        if($criteria['lang']!='') $this->lang = $criteria['lang'];
        if($criteria['fb_sdk']!='') $this->fb_sdk = $criteria['fb_sdk'];
       
        if($witness=='') {
            if($this->fb_sdk=='1') echo '<div id="fb-root"></div><script src="http://connect.facebook.net/'.$this->lang.'/all.js#appId='.$this->app_id.'&amp;xfbml=1"></script>';
            $witness=1;
        }
    }

function get_activity_feed($criteria=array()) {
        $domain = $criteria['domain'];
        $width = $criteria['width'];
        $height = $criteria['height'];
        $colorscheme = $criteria['colorscheme'];
        $header = $criteria['header'];
        $recommendations = $criteria['recommendations'];
        $border_color = $criteria['border_color'];
        $font = $criteria['font'];
       
        if($domain=='') $domain = '';
        if($width=='') $width = '300';
        if($height=='') $height = '300';
        if($colorscheme=='') $colorscheme = 'light'; //light, dark
        if($header=='') $header = 'true';
        if($recommendations=='') $recommendations = 'false';
        if($border_color=='') $border_color = '';
        if($font=='') $font = ''; //'arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana'
       
        $content = '<iframe src="http://www.facebook.com/plugins/activity.php?site='.$domain.'&amp;width='.$width.'&amp;height='.$height.'&amp;header='.$header.'&amp;colorscheme='.$colorscheme.'&amp;font='.$font.'&amp;border_color='.$border_color.'&amp;recommendations='.$recommendations.'" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:'.$width.'px; height:'.$height.'px;" allowTransparency="true"></iframe>';
       
        return $content;
    }



2) call this function activity file ( activity.php )

<?php
include_once('Facebook_plugins_class.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PhpWeb Blog</title>
</head>
<body>
<h3>Facebook Activity Feed</h3>
<div>
    <?php
    $f1 = new Facebook_plugins_class();
    $display = $f1->get_activity_feed(array('domain'=>'themeforest.net', 'width'=>'460'));
    echo $display;
    ?>
</div>
</body>
</html>


 

No comments:

Post a Comment

Thanks....