PHP code example of illagrenan / nette-facebook-connect

1. Go to this page and download the library: Download illagrenan/nette-facebook-connect library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

illagrenan / nette-facebook-connect example snippets


\Illagrenan\Facebook\DI\FacebookConnectExtension::register($configurator);


abstract class BasePresenter extends \Nette\Application\UI\Presenter
{     
    /**
     * @var \Illagrenan\Facebook\FacebookConnect
     */
    protected $facebookConnect;
     
    public function injectFacebookConnectClient(\Illagrenan\Facebook\FacebookConnect $facebookConnect)
    {        
        $this->facebookConnect = $facebookConnect;
    }

}



use Nette\Diagnostics\Debugger;

class HomepagePresenter extends BasePresenter
{

    public function renderDefault()
    {
        // Autorizoval uživatel naši aplikaci?
        if ($this->facebookConnect->isLoggedIn() === FALSE)
        {
            // Volitelně můžeme změnit URL, na kterou bude uživatel z Facebooku navrácen
            // Přijímá buď nette zápis odkazů nebo absolutní URL
            $this->facebookConnect->setRedirectUri("Homepage:default");


            // Přihlásíme ho přesměrováním na Login_URL
            $this->facebookConnect->login();
        }
        else // Uživatel je přihlášený v aplikaci
        {
            /* @var $user Illagrenan\Facebook\FacebookUser */
            $user                 = $this->facebookConnect->getFacebookUser();
            $this->template->user = $user;

            Debugger::dump($user);
        }
    }

    /**
     * Přesměruje uživatele na přihlašovací stránku aplikace (na facebook.com)
     */
    public function handleFacebookLogin()
    {
        $this->facebookConnect->login();
    }

    /**
     * Odhlásí uživatele z aplikace A z Facebooku
     */
    public function handleFacebookLogout()
    {
        $this->facebookConnect->logout();
    }

}
bash
$ php composer.phar install