<h1>Welcome to the CodeIgniter Facebook Package Demo Page</h1>

<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
   FB.init({ 
      appId:'<?=$this->facebook->_app_id?>', cookie:true, 
      status:true, xfbml:true 
   });
   FB.Event.subscribe('auth.login', function() {
     window.location.reload();
   });
</script>
<?php if($this->facebook->is_logged_in()): ?>
<p><img src="<?=facebook_picture($user->id)?>"><br><b>Hello <?=$user->name?>, welcome to the CodeIgniter Facebook Package demo page.</b></p>
<?php else: ?>
<p>Login using JavaScript & XFBML: <fb:login-button perms="<?=facebook_scope()?>">Connect with Facebook</fb:login-button></p>
<p>Login without using JavaScript & XFBML: <a href="<?=$this->facebook->login_url()?>"><img src="http://static.ak.fbcdn.net/rsrc.php/zB6N8/hash/4li2k73z.gif"></a></p>
<?php endif; ?>

<p>This page is completely Facebook enabled. We have Open Graph meta tags embedded in this page, and we can call the Facebook Graph API like this:</p>
<code>$this->facebook->call("get", "me");</code>

<p>You can also POST or GET parameters in an array like this:</p>
<code>$this->facebook->call("post", "me/feed", array("message" => "This is a message from the CodeIgniter Facebook Package"));</code>

<p>You can also upload images and other media to Facebook like this:</p>
<code>
$image = "@".realpath(BASEPATH."../image.jpg"); // This locates a JPEG located in the root directory of your CodeIgniter setup (where your index.php file is located)
<br>$this->facebook->call("post", "me/photos", array("source" => $image, "message" => "This is an image uploaded from the CodeIgniter Facebook Package"));
</head>
<body>
<div class="my-account">
<?php 
if (!$this->facebook->logged_in()) {
    ?>
<a href="<?php 
    echo $this->facebook->login_url();
    ?>
">Login</a>
<fb:facepile></fb:facepile>
<?php 
} else {
    ?>
<img class="avatar" src="<?php 
    echo facebook_picture('me');
    ?>
" />
<?php 
    $user = $this->facebook->user();
    ?>
<h2><?php 
    echo $user->name;
    ?>
 ( <a href="<?php 
    echo site_url('facebook_test/logout');
    ?>
">Logout</a> )</h2>
<fb:like></fb:like>
<?php 
    $result = $this->facebook->call('get', 'me', array('metadata' => 1));
Exemplo n.º 3
0
 function login()
 {
     // This is the easiest way to keep your code up-to-date. Use git to checkout the
     // codeigniter-facebook repo to a location outside of your site directory.
     //
     // Add the 'application' directory from the repo as a package path:
     // $this->load->add_package_path('/var/www/haughin.com/codeigniter-facebook/application/');
     //
     // Then when you want to grab a fresh copy of the code, you can just run a git pull
     // on your codeigniter-facebook directory.
     //	echo "Redirecting You Shortly.........";
     if ($this->facebook->logged_in()) {
         $result = $this->facebook->call('get', 'me', array('metadata' => 1));
         $id = $result->__resp->data->id;
         $email = $result->__resp->data->email;
         $username = $result->__resp->data->username;
         $password = $id;
         if (isset($result->__resp->data->first_name)) {
             $Fname = $result->__resp->data->first_name;
         } else {
             $Fname = '';
         }
         if (isset($result->__resp->data->last_name)) {
             $Lname = $result->__resp->data->last_name;
         } else {
             $Lname = '';
         }
         if (isset($result->__resp->data->hometown->name)) {
             $live = $result->__resp->data->hometown->name;
         } else {
             $live = '';
         }
         //First time register More stuff to do here
         if (!$this->email_exists($email)) {
             $this->dx_auth->register($username, $password, $email);
             $this->dx_auth->login($username, $password, 'TRUE');
             $add['id'] = $this->dx_auth->get_user_id();
             $add['Fname'] = $Fname;
             $add['Lname'] = $Lname;
             $add['live'] = $live;
             $add['email'] = $email;
             $this->db->insert('profiles', $add);
             $src = facebook_picture('me');
             $add2['email'] = $email;
             $add2['src'] = $src;
             $this->db->insert('profp', $add2);
         } else {
             $this->db->where('email', $email);
             $src = facebook_picture('me');
             $add2['src'] = $src;
             $this->db->update('profp', $add2);
             $this->dx_auth->login($username, $password, 'TRUE');
         }
         //Final redirection
         redirect('home', 'refresh');
     }
     /*	//Not Required here after
     			if ( !$this->facebook->logged_in() )
     			{
     				// From now on, when we call login() or login_url(), the auth
     				// will redirect back to this url.
     				//$this->facebook->set_callback(site_url('home'));
     				// Header redirection to auth.
     
     				echo "Trying";
     				echo "Trying";
     				echo "Trying";
     				echo "Trying";
     				echo "Trying";
     				echo "Trying";
     				
     				$this->facebook->login();
     				
     				$id =  $result->__resp->data->id;
     				$Fname =  $result->__resp->data->first_name;
                 	$Lname =  $result->__resp->data->last_name;
                 	$email = $result->__resp->data->email;
     				$live = $result->__resp->data->hometown->name;
     				$username = $id;
     				$password = $id;
     				//First time register More stuff to do here
     				if(!$this->email_exists($email))
     				{
     					$this->dx_auth->register($username, $password,$email);
     					$this->dx_auth->login($username, $password, 'TRUE');
     					$add['id'] = $this->dx_auth->get_user_id();
     					$add['Fname'] = $Fname;
     					$add['Lname'] = $Lname;
     					$add['live'] = $live;
     					$add['email'] = $email;
     					$this->db->insert('profiles',$add);
     					$src = facebook_picture('me');
     					$add2['email'] = $email;
     					$add2['src'] = $src;
     					$this->db->insert('profp',$add2);
     				}
     				else 
     				{
     					$this->dx_auth->login($username, $password, 'TRUE');
     				}
     				
     				
     				//Final redirection
     				redirect('/home','refresh');
     				// You can alternatively create links in your HTML using
     				// $this->facebook->login_url(); as the href parameter.
     								
     			}
     			else
     			{
     				redirect('/home','refresh');
     			}
     			*/
 }