WebWall version 1.1

- Changed uLogin auth into Facebook Auth

FAQ

How to add Facebook authentification?
-------------------------------------
- Update application files to version 1.1.
- Copy your Facebook App ID and App secret. Aplication should be enabled.
- In Settings tab > Advanced find "Valid OAuth redirect URIs" and add url of your website like: http:// [youdomain.com] /core/modules/auth.php. 
      So, for xandr.me will be: http://xandr.me/core/modules/auth.php
- Open core.php and find line with FB_ID and FB_SECRET
      FB_ID - Here is your App ID
      FB_SECRET - Here is your App secret key


--------------------------------------------------------------------
Edit core.php - add code after define("AUTHOR", "http://xandr.me/"):
--------------------------------------------------------------------

	/* FACEBOOK AUTH */
	define("FB_ID","255556901270808"); // YOUR Client ID
	define("FB_SECRET","2b8c76b6322361da74c1087092612d99"); // YOUR Client secret

--------------------------------------------------------------------
Edit core/tpl/index.tpl - replace code:
--------------------------------------------------------------------

	<div class="row">
      	<script src="//ulogin.ru/js/ulogin.js"></script>	
        <div id="uLogin" x-ulogin-params="display=buttons;optional=first_name,last_name,bdate,sex,photo,photo_big,country,city;providers=facebook,vkontakte,twitter,googleplus;redirect_uri=http%3A%2F%2F<?php echo SITE_DOMAIN; ?>%2Fsite%2Fauth;receiver=http%3A%2F%2F<?php echo SITE_DOMAIN; ?>%2Fsite%2Fulogin">
          <div class="col-xs-6 col-sm-6 col-md-6">
            <a class="btn btn-lg btn-primary btn-block" x-ulogin-button = "facebook">Facebook</a>
          </div>
          <div class="col-xs-6 col-sm-6 col-md-6">
            <a class="btn btn-lg btn-info btn-block" x-ulogin-button = "twitter">Twitter</a>
          </div>
        </div>
      </div>

    INTO-------------

    <div class="row">
      	<div class="col-xs-12 col-sm-12 col-md-12">
          <?php
            $client_id = FB_ID; // YOUR Client ID
            $client_secret = FB_SECRET; // YOUR Client secret
            $redirect_uri = 'http://'.SITE_DOMAIN.'/core/modules/auth.php';
            $url = 'https://www.facebook.com/dialog/oauth';
            $params = array(
                'client_id'     => $client_id,
                'redirect_uri'  => $redirect_uri,
                'response_type' => 'code',
                'scope'         => 'email,user_birthday'
            );
            echo $link = '<a class="btn btn-lg btn-primary btn-block" href="' . $url . '?' . urldecode(http_build_query($params)) . '">Facebook</a>';
          ?>
        </div>
      </div>


---------------------------------------
Edit core/tpl/login.tpl - replace code:
---------------------------------------

	<div class="row">
        <script src="//ulogin.ru/js/ulogin.js"></script>  
        <div id="uLogin" x-ulogin-params="display=buttons;optional=first_name,last_name,bdate,sex,photo,photo_big,country,city;providers=facebook,vkontakte,twitter,googleplus;redirect_uri=http%3A%2F%2F<?php echo SITE_DOMAIN; ?>%2Fsite%2Fauth;receiver=http%3A%2F%2F<?php echo SITE_DOMAIN; ?>%2Fsite%2Fulogin">
          <div class="col-xs-6 col-sm-6 col-md-6">
            <a class="btn btn-lg btn-primary btn-block" x-ulogin-button = "facebook">Facebook</a>
          </div>
          <div class="col-xs-6 col-sm-6 col-md-6">
            <a class="btn btn-lg btn-info btn-block" x-ulogin-button = "twitter">Twitter</a>
          </div>
        </div>
      </div>

    INTO---------------

    <div class="row">
      	<div class="col-xs-12 col-sm-12 col-md-12">
          <?php
            $client_id = FB_ID; // YOUR Client ID
            $client_secret = FB_SECRET; // YOUR Client secret
            $redirect_uri = 'http://'.SITE_DOMAIN.'/core/modules/auth.php';
            $url = 'https://www.facebook.com/dialog/oauth';
            $params = array(
                'client_id'     => $client_id,
                'redirect_uri'  => $redirect_uri,
                'response_type' => 'code',
                'scope'         => 'email,user_birthday'
            );
            echo $link = '<a class="btn btn-lg btn-primary btn-block" href="' . $url . '?' . urldecode(http_build_query($params)) . '">Facebook</a>';
          ?>
        </div>
    </div>


--------------------------------------------------
Edit core/modules/auth.php - change all code into:
--------------------------------------------------

<?php
$root = dirname( dirname( dirname(__FILE__) ) );
require_once "$root/core.php";
if (isset($_GET['code'])) 
{
	$client_id = FB_ID; // YOUR Client ID
	$client_secret = FB_SECRET; // YOUR Client secret
	$redirect_uri = 'http://'.SITE_DOMAIN.'/core/modules/auth.php';
	$url = 'https://www.facebook.com/dialog/oauth';
	$params = array(
	    'client_id'     => $client_id,
	    'redirect_uri'  => $redirect_uri,
	    'response_type' => 'code',
	    'scope'         => 'email,user_birthday'
	);
	$result = false;
	$params = array(
	    'client_id'     => $client_id,
	    'redirect_uri'  => $redirect_uri,
	    'client_secret' => $client_secret,
	    'code'          => $_GET['code']
	);
	$url = 'https://graph.facebook.com/oauth/access_token';
	$tokenInfo = null;
	parse_str(file_get_contents($url . '?' . http_build_query($params)), $tokenInfo);
	if(count($tokenInfo) > 0 && isset($tokenInfo['access_token'])) 
	{
	    $params = array('access_token' => $tokenInfo['access_token']);
		$userInfo = json_decode(file_get_contents('https://graph.facebook.com/me' . '?' . urldecode(http_build_query($params))), true);
		if (isset($userInfo['id'])) 
		{
	        $userInfo = $userInfo;
	        $result = true;
	    }
	}
	if ($result) 
	{
		session_start();
		unset($_SESSION['regnetwork']);
		unset($_SESSION['regid']);
		unset($_SESSION['regfirst_name']);
		unset($_SESSION['reglast_name']);
		unset($_SESSION['regbdate']);
		unset($_SESSION['regphoto_big']);
		unset($_SESSION['regcountry']);
		unset($_SESSION['regcity']);
		$_SESSION['regnetwork'] = 'facebook';
		$_SESSION['regid'] = $userInfo['link'];
		$_SESSION['regfirst_name'] = $userInfo['first_name'];
		$_SESSION['reglast_name'] = $userInfo['last_name'];
		$_SESSION['regbdate'] = 'facebook';
		$_SESSION['regphoto_big'] = 'http://graph.facebook.com/' . $userInfo['username'] . '/picture?type=large';
		$_SESSION['regcountry'] = 'f';
		$_SESSION['regcity'] = 'f';
		$engine_session->checkcookies("", "", 'facebook', $userInfo['link']);
	}
}
?>