Facebook.php 1.83 KB
<?php
/**
 * This needs to go in the <html tag
 * xmlns:fb="http://www.facebook.com/2008/fbml"
 *
 * http://wpdev.tenzinghost.com
 * API Key:    83f54e078b9aa0e303bba959dc0a566f
 * App Secret: e542aca35ab698121fa5917211013a41
 * App ID:     105917066126941
 * 
 * http://wp.cb
 * API Key:    3bcccfd8c28c52197141266d9e417649
 * App Secret: 9bfcd828bc6ccef12336dea57df93ecb
 * App ID:     138943536118944
 */

namespace Tz\WordPress\Tools\Auth\Facebook;

use Tz\WordPress\Tools;
use Tz\WordPress\Tools\ShortCodes as SC;

use InvalidArgumentException;

const OPTION_NAME = 'tz_auth_fb';

    call_user_func(function() {
        SC\add_shortcodes(__NAMESPACE__ . '\ShortCodes');
        Vars::$options = new Tools\WP_Option(OPTION_NAME);

        if (is_admin()) {
            require_once(__DIR__ . DIRECTORY_SEPARATOR . 'Settings.php');
        }
    });

function loadJSSDK() {
    return '
<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({appId: \'' . Vars::$options['application_id'] . '\', status: true, cookie: true, xfbml: true});
    FB.Event.subscribe(\'auth.login\', function(response) { window.location.reload(); });
  };
  (function() {
    var e = document.createElement(\'script\'); e.async = true;
    e.src = document.location.protocol + \'//connect.facebook.net/en_US/all.js\';
    document.getElementById(\'fb-root\').appendChild(e);
  }());
</script>
    ';
}

function drawLoginButton($value = 'Login') {
    echo '<fb:login-button></fb:login-button>';
//    echo '<a class="fb_button fb_button_medium"><span class="fb_button_text">' . $value . '</span></a>';
}

class Vars {
    public static $options = false;
}

class ShortCodes {
    public static function fb_login_button() {
        ob_start();
        drawLoginButton();
        $btn = ob_get_contents();
        ob_end_clean();

        return $btn;
    }
}
?>