Пример #1
0
function jfb_admin_page()
{
    global $jfb_name, $jfb_version, $opt_jfb_app_token;
    global $opt_jfb_app_id, $opt_jfb_api_key, $opt_jfb_api_sec, $opt_jfb_email_to, $opt_jfb_email_logs, $opt_jfb_delay_redir, $jfb_homepage;
    global $opt_jfb_ask_perms, $opt_jfb_mod_done, $opt_jfb_ask_stream, $opt_jfb_stream_content;
    global $opt_jfb_bp_avatars, $opt_jfb_wp_avatars, $opt_jfb_valid, $opt_jfb_fulllogerr, $opt_jfb_disablenonce, $opt_jfb_show_credit;
    global $opt_jfb_username_style, $opt_jfb_hidesponsor;
    ?>
    <div class="wrap">
     <h2><?php 
    echo $jfb_name;
    ?>
 Options</h2>
    <?php 
    //Show applicable warnings (only on this panel's page; global warnings are above)
    if (class_exists('Facebook')) {
        ?>
<div class="error"><p><strong>Warning:</strong> Another plugin has included the Facebook API throughout all of Wordpress.  I suggest you contact that plugin's author and ask them to include it only in pages where it's actually needed.<br /><br />Things may work fine as-is, but *if* the API version included by the other plugin is older than the one required by WP-FB AutoConnect, it's possible that the login process could fail.</p></div><?php 
    }
    if (version_compare('5', PHP_VERSION, ">")) {
        ?>
<div class="error"><p>Sorry, but as of v1.3.0, WP-FB AutoConnect requires PHP5.</p></div><?php 
        die;
    }
    if (function_exists('is_multisite') && is_multisite() && !jfb_premium()) {
        ?>
<div class="error"><p><strong>Warning:</strong> Wordpress MultiSite is only fully supported by the premium version of this plugin; please see <a href="<?php 
        echo $jfb_homepage;
        ?>
#premium"><b>here</b></a> for details.</p></div><?php 
    }
    if (file_exists(realpath(dirname(__FILE__)) . "/WP-FB-AutoConnect-Premium.php")) {
        ?>
<div class="error"><p><strong>Notice:</strong> You seem to've uploaded the premium addon to the wrong directory.<br/><br/>
            As per the <a target="instructs" href="<?php 
        echo $jfb_homepage;
        ?>
#premium"><b>setup instructions</b></a>, the "WP-FB-AutoConnect-Premium.php" file goes in your <i>plugins</i> directory (i.e. wp-content/plugins/WP-FB-AutoConnect-Premium.php), not the WP-FB-AutoConnect directory (i.e. wp-content/plugins/wp-fb-autoconnect/WP-FB-AutoConnect-Premium.php). This is to prevent it from getting overwritten when you auto-update the core plugin.</p></div>
        <?php 
    }
    do_action('wpfb_admin_messages');
    //Which tab to show by default
    $shownTab = get_option($opt_jfb_valid) ? 1 : 0;
    //Update options
    if (isset($_POST['fb_opts_updated'])) {
        //When saving the Facebook options, make sure the key and secret are valid...
        update_option($opt_jfb_valid, 0);
        $shownTab = 0;
        $result = jfb_api_get("https://graph.facebook.com/" . $_POST[$opt_jfb_api_key]);
        if (!$result) {
            ?>
<div class="error"><p>Error: Failed to validate your App ID and Secret.  Response: Empty Reply.<br />Are you sure you entered your App ID correctly?</p></div><?php 
        } elseif (isset($result['error'])) {
            ?>
<div class="error"><p>Error: Failed to validate your App ID and Secret.  Response: <?php 
            echo isset($result['error']['message']) ? $result['error']['message'] : "Unknown";
            ?>
.<br />Are you sure you entered your App ID correctly?</p></div><?php 
        } elseif ($result['id'] != $_POST[$opt_jfb_api_key]) {
            ?>
<div class="error"><p>Error: Failed to validate your App ID and Secret.  Response: ID Mismatch.</p></div><?php 
        } else {
            //If we got here, we know the App ID is correct.  Now try to get an app token and store it in the options table; if this works we know the secret is correct too.
            //Note: this plugin doesn't actually use the app-token; I simply cache it so it can be accessible to users wishing to further interact with Facebook via hooks & filters.
            //Note: App tokens never expire unless the app secret is refreshed.
            $response = wp_remote_get("https://graph.facebook.com/oauth/access_token?client_id=" . $_POST[$opt_jfb_api_key] . "&client_secret=" . $_POST[$opt_jfb_api_sec] . "&grant_type=client_credentials", array('sslverify' => false));
            if (is_array($response) && strpos($response['body'], 'access_token=') !== FALSE) {
                //We're valid!
                $shownTab = 1;
                update_option($opt_jfb_valid, 1);
                update_option($opt_jfb_app_token, substr($response['body'], 13));
                if (get_option($opt_jfb_api_key) != $_POST[$opt_jfb_api_key]) {
                    jfb_auth($jfb_name, $jfb_version, 2, "SET: " . $message);
                }
                ?>
<div class="updated"><p><strong>Successfully connected with "<?php 
                echo $result['name'];
                ?>
" (ID <?php 
                echo $result['id'];
                ?>
)</strong></p></div><?php 
            } else {
                ?>
<div class="error"><p>Error: Failed to validate your App ID and Secret.<br />Are you sure you entered your App Secret correctly?</p></div><?php 
            }
        }
        //We can save these either way, because if "valid" isn't set, a button won't be shown.
        update_option($opt_jfb_app_id, $result['id']);
        update_option($opt_jfb_api_key, $_POST[$opt_jfb_api_key]);
        update_option($opt_jfb_api_sec, $_POST[$opt_jfb_api_sec]);
    }
    if (isset($_POST['main_opts_updated'])) {
        $shownTab = 1;
        update_option($opt_jfb_ask_perms, $_POST[$opt_jfb_ask_perms]);
        update_option($opt_jfb_ask_stream, $_POST[$opt_jfb_ask_stream]);
        update_option($opt_jfb_wp_avatars, $_POST[$opt_jfb_wp_avatars]);
        update_option($opt_jfb_stream_content, $_POST[$opt_jfb_stream_content]);
        update_option($opt_jfb_show_credit, $_POST[$opt_jfb_show_credit]);
        update_option($opt_jfb_email_to, $_POST[$opt_jfb_email_to]);
        update_option($opt_jfb_email_logs, $_POST[$opt_jfb_email_logs]);
        update_option($opt_jfb_delay_redir, $_POST[$opt_jfb_delay_redir]);
        update_option($opt_jfb_fulllogerr, $_POST[$opt_jfb_fulllogerr]);
        update_option($opt_jfb_disablenonce, $_POST[$opt_jfb_disablenonce]);
        update_option($opt_jfb_username_style, $_POST[$opt_jfb_username_style]);
        ?>
<div class="updated"><p><strong>Options saved.</strong></p></div><?php 
    }
    if (isset($_POST['prem_opts_updated']) && function_exists('jfb_update_premium_opts')) {
        $shownTab = 2;
        jfb_update_premium_opts();
    }
    if (isset($_POST['remove_all_settings'])) {
        $shownTab = 0;
        delete_option($opt_jfb_api_key);
        delete_option($opt_jfb_api_sec);
        delete_option($opt_jfb_email_to);
        delete_option($opt_jfb_email_logs);
        delete_option($opt_jfb_delay_redir);
        delete_option($opt_jfb_ask_perms);
        delete_option($opt_jfb_ask_stream);
        delete_option($opt_jfb_stream_content);
        delete_option($opt_jfb_mod_done);
        delete_option($opt_jfb_valid);
        delete_option($opt_jfb_app_token);
        delete_option($opt_jfb_bp_avatars);
        delete_option($opt_jfb_wp_avatars);
        delete_option($opt_jfb_fulllogerr);
        delete_option($opt_jfb_disablenonce);
        delete_option($opt_jfb_show_credit);
        delete_option($opt_jfb_username_style);
        delete_option($opt_jfb_hidesponsor);
        if (function_exists('jfb_delete_premium_opts')) {
            jfb_delete_premium_opts();
        }
        ?>
<div class="updated"><p><strong><?php 
        _e('All plugin settings have been cleared.');
        ?>
</strong></p></div><?php 
    }
    ?>
    
    <?php 
    if (isset($_REQUEST[$opt_jfb_hidesponsor])) {
        update_option($opt_jfb_hidesponsor, $_REQUEST[$opt_jfb_hidesponsor]);
    }
    if (!get_option($opt_jfb_hidesponsor) && !defined('JFB_PREMIUM')) {
        ?>
      	<!-- Sponsorship message *was* here, until Automattic demanded they be removed from all plugins - see http://gregsplugins.com/lib/2011/11/26/automattic-bullies/ -->
     <?php 
    }
    ?>
     

    <!-- Tab Navigation -->
    <?php 
    //Define some variables that'll be used for our tab-switching
    $allTabsClass = "jfb_admin_tab";
    $allTabBtnsClass = "jfb_admin_tab_btn";
    $tabIds = array("jfb_admin_fbsetup", "jfb_admin_basicoptions", "jfb_admin_premiumoptions", "jfb_admin_uninstall", "jfb_admin_supportinfo");
    $tabNames = array("Facebook Setup", "Basic Options", "Premium Options", "Uninstall", "Support Info");
    ?>
    
    <script type="text/javascript">
        function jfb_swap_tabs(show_tab_num) 
        {
            //Find the ID of the tab we want to show
            var tabIds = <?php 
    echo json_encode($tabIds);
    ?>
;
            var show_tab_id = tabIds[show_tab_num];
            
            //Hide all the tabs, then show just the one specified
        	jQuery(".<?php 
    echo $allTabsClass;
    ?>
").hide();
        	jQuery("#" + show_tab_id).show();

        	//Unhighlight all the tab buttons, then highlight just the one specified
        	jQuery(".<?php 
    echo $allTabBtnsClass;
    ?>
").attr("class", "<?php 
    echo $allTabBtnsClass;
    ?>
");
        	jQuery("#" + show_tab_id + "_btn").addClass("jfb-admin_tab_selected");
		}
		
		//When the page is loaded, if there's a hash like "#1, #2, etc" in the URL, switch to that tab.
		//This handles restoring the previously-displayed tab after a page refresh.
		jQuery(document).ready(function() 
		{
    		if(window.location.hash)
    		{
    		    var num = parseInt(window.location.hash.substr(1));
    		    if( !isNaN(num) )
    		      jfb_swap_tabs(num);
    		}
        });
	</script>
	        
    <div>     
         <ul class="jfb-admin_tabs"><?php 
    for ($i = 0; $i < count($tabIds); $i++) {
        ?>
<li id="<?php 
        echo $tabIds[$i];
        ?>
_btn" class="<?php 
        echo $allTabBtnsClass;
        ?>
 <?php 
        echo $shownTab == $i ? "jfb-admin_tab_selected" : "";
        ?>
"><a href="#<?php 
        echo $i;
        ?>
" onclick="jfb_swap_tabs('<?php 
        echo $i;
        ?>
');"><?php 
        echo $tabNames[$i];
        ?>
</a></li><?php 
    }
    ?>
</ul>
     </div>
     
    <div class="jfb-admin_wrapper">
        <div class="<?php 
    echo $allTabsClass;
    ?>
" id="<?php 
    echo $tabIds[0];
    ?>
" style="display:<?php 
    echo $shownTab == 0 ? "block" : "none";
    ?>
">
        	<h3>Setup Instructions</h3>
            To allow your users to login with their Facebook accounts, you must first setup a Facebook Application for your website:<br /><br />
            <ol>
              <li>Visit <a href="http://developers.facebook.com/apps" target="_lnk">developers.facebook.com/apps</a> and click the "Create New App" button.</li>
              <li>Type in a name (i.e. the name of your website) and click "Continue."  This is the name your users will see on the Facebook login popup.</li>
              <li>Facebook may now require you to verify your account before continuing (see <a target="_fbInfo" href="https://developers.facebook.com/blog/post/386/">here</a> for more information).</li>
              <li>Once your app has been created, scroll down and fill in your "Site URL" under "Select how your app integrates with Facebook -&gt;"Website."  Note: http://example.com/ and http://www.example.com/ are <i>not</i> the same.</li>
              <li>Click "Save Changes."</li>
              <li>Copy the App ID and App Secret to the boxes below.</li>
              <li>Click "Save" below.</li>
            </ol>
            <br />That's it!  Now you can add this plugin's <a href="<?php 
    echo admin_url('widgets.php');
    ?>
">sidebar widget</a>, or if you're using BuddyPress, a Facebook button will be automatically added to its built-in login panel.<br /><br />
            For more complete documentation and help, visit the <a href="<?php 
    echo $jfb_homepage;
    ?>
">plugin homepage</a>.<br />
             
            <br />
            <hr />
            
            <h3>Facebook Connect</h3>
            <form name="formFacebook" method="post" action="">
                <input type="text" size="40" name="<?php 
    echo $opt_jfb_api_key;
    ?>
" value="<?php 
    echo get_option($opt_jfb_api_key);
    ?>
" /> App ID<br />
                <input type="text" size="40" name="<?php 
    echo $opt_jfb_api_sec;
    ?>
" value="<?php 
    echo get_option($opt_jfb_api_sec);
    ?>
" /> App Secret
                <input type="hidden" name="fb_opts_updated" value="1" />
                <div class="submit"><input type="submit" name="Submit" value="Connect" /></div>
            </form>
        </div> <!-- End Tab -->
        
        <div class="<?php 
    echo $allTabsClass;
    ?>
" id="<?php 
    echo $tabIds[1];
    ?>
" style="display:<?php 
    echo $shownTab == 1 ? "block" : "none";
    ?>
">
            <?php 
    if (!get_option($opt_jfb_valid)) {
        echo "<div class=\"jfb-admin_warning\"><i><b>You must enter a valid APP ID and Secret under the \"Facebook Setup\" tab before this plugin will function.</b></i></div>";
    }
    ?>
            <h3>Basic Options</h3>
            <form name="formMainOptions" method="post" action="">
                <b>Autoregistered Usernames:</b><br />
                <input type="radio" name="<?php 
    echo $opt_jfb_username_style;
    ?>
" value="0" <?php 
    echo get_option($opt_jfb_username_style) == 0 ? "checked='checked'" : "";
    ?>
 >Based on Facebook ID (i.e. FB_123456)<br />
                <input type="radio" name="<?php 
    echo $opt_jfb_username_style;
    ?>
" value="1" <?php 
    echo get_option($opt_jfb_username_style) == 1 ? "checked='checked'" : "";
    ?>
 >Based on real name with prefix (i.e. FB_John_Smith)<br />
                <input type="radio" name="<?php 
    echo $opt_jfb_username_style;
    ?>
" value="3" <?php 
    echo get_option($opt_jfb_username_style) == 3 ? "checked='checked'" : "";
    ?>
 >Based on real name without prefix (i.e. John_Smith) <i><b>(Recommended for BuddyPress)</b></i><br />
                <input type="radio" name="<?php 
    echo $opt_jfb_username_style;
    ?>
" value="2" <?php 
    echo get_option($opt_jfb_username_style) == 2 ? "checked='checked'" : "";
    ?>
 >Legacy Format (i.e. John.Smith) <i><b>(Not Recommended, <dfn title="Although the original 'BuddyPress-friendly' username format included a period, I later learned that this creates issues with author links in Wordpress.  I've left the option here for legacy support, but advise against using it (unless you have only one author on your blog, in which case Facebook-connected users won't have author links and so it doesn't matter).  If you do have multiple authors and are experiencing broken author links, changing this option will fix it for all NEW users, but you may want to consider fixing your existing users by replacing all of the '.'s with '_'s in the 'user_nicename' field of the 'wp_users' database table.">mouseover for why</dfn>)</b></i><br /><br />
            
                <b>E-Mail:</b><br />
                <input type="checkbox" name="<?php 
    echo $opt_jfb_ask_perms;
    ?>
" value="1" <?php 
    echo get_option($opt_jfb_ask_perms) ? 'checked="checked"' : '';
    ?>
 /> Request permission to get the connecting user's email address<br />
        
                <br /><b>Announcement:</b><br />
        		<?php 
    add_option($opt_jfb_stream_content, "has connected to " . get_option('blogname') . " with WP-FB AutoConnect.");
    ?>
        		<input type="checkbox" name="<?php 
    echo $opt_jfb_ask_stream;
    ?>
" value="1" <?php 
    echo get_option($opt_jfb_ask_stream) ? 'checked="checked"' : '';
    ?>
 /> Request permission to post the following announcement on users' Facebook walls when they connect for the first time:<br />
        		<input type="text" size="100" name="<?php 
    echo $opt_jfb_stream_content;
    ?>
" value="<?php 
    echo get_option($opt_jfb_stream_content);
    ?>
" /><br />
        
        		<br /><b>Avatars:</b><br />
                <input type="checkbox" name="<?php 
    echo $opt_jfb_wp_avatars;
    ?>
" value="1" <?php 
    echo get_option($opt_jfb_wp_avatars) ? 'checked="checked"' : '';
    ?>
 /> Use Facebook profile pictures as avatars<br />
        
                <br /><b>Credit:</b><br />
                <input type="checkbox" name="<?php 
    echo $opt_jfb_show_credit;
    ?>
" value="1" <?php 
    echo get_option($opt_jfb_show_credit) ? 'checked="checked"' : '';
    ?>
 /> Display a "Powered By" link in the blog footer (would be appreciated! :))<br />
        
        		<br /><b>Debug:</b><br />
        		<?php 
    add_option($opt_jfb_email_to, get_bloginfo('admin_email'));
    ?>
        		<input type="checkbox" name="<?php 
    echo $opt_jfb_email_logs;
    ?>
" value="1" <?php 
    echo get_option($opt_jfb_email_logs) ? 'checked="checked"' : '';
    ?>
 /> Send all event logs to <input type="text" size="40" name="<?php 
    echo $opt_jfb_email_to;
    ?>
" value="<?php 
    echo get_option($opt_jfb_email_to);
    ?>
" /><br />
        		<input type="checkbox" name="<?php 
    echo $opt_jfb_disablenonce;
    ?>
" value="1" <?php 
    echo get_option($opt_jfb_disablenonce) ? 'checked="checked"' : '';
    ?>
 /> Disable nonce security check (Not recommended)<br />
                <input type="checkbox" name="<?php 
    echo $opt_jfb_delay_redir;
    ?>
" value="1" <?php 
    echo get_option($opt_jfb_delay_redir) ? 'checked="checked"' : '';
    ?>
 /> Delay redirect after login (<i><u>Not for production sites!</u></i>)<br />
                <input type="checkbox" name="<?php 
    echo $opt_jfb_fulllogerr;
    ?>
" value="1" <?php 
    echo get_option($opt_jfb_fulllogerr) ? 'checked="checked"' : '';
    ?>
 /> Show full log on error (<i><u>Not for production sites!</u></i>)<br />
                <input type="hidden" name="main_opts_updated" value="1" />
                <div class="submit"><input type="submit" name="Submit" value="Save" /></div>
            </form>
    	</div><!-- End Tab -->
    
    	<div class="<?php 
    echo $allTabsClass;
    ?>
" id="<?php 
    echo $tabIds[2];
    ?>
" style="display:<?php 
    echo $shownTab == 2 ? "block" : "none";
    ?>
">
            <?php 
    if (!get_option($opt_jfb_valid)) {
        echo "<div class=\"jfb-admin_warning\"><i><b>You must enter a valid APP ID and Secret under the \"Facebook Setup\" tab before this plugin will function.</b></i></div>";
    }
    if (function_exists('jfb_output_premium_panel')) {
        jfb_output_premium_panel();
    } else {
        jfb_output_premium_panel_tease();
    }
    ?>
        </div> <!-- End Tab -->
        
        <div class="<?php 
    echo $allTabsClass;
    ?>
" id="<?php 
    echo $tabIds[3];
    ?>
" style="display:<?php 
    echo $shownTab == 3 ? "block" : "none";
    ?>
">
            <h3>Delete All Plugin Options</h3>
            The following button will <i>permanently</i> delete all of this plugin's options from your Wordpress database, as if it had never been installed.  Use with care!
            <form name="formDebugOptions" method="post" action="">
                <input type="hidden" name="remove_all_settings" value="1" />
                <div class="submit"><input type="submit" name="Submit" value="Delete" /></div>
            </form>
        </div> <!-- End Tab -->
        
        <div class="<?php 
    echo $allTabsClass;
    ?>
" id="<?php 
    echo $tabIds[4];
    ?>
" style="display:<?php 
    echo $shownTab == 4 ? "block" : "none";
    ?>
">
            <h3>Support Information</h3>
            <div style="width:600px;">
            Before submitting a support request, please make sure to carefully read all the documentation and FAQs on the <a href="<?php 
    echo $jfb_homepage;
    ?>
#faq" target="_support">plugin homepage</a>.  Every problem that's ever been reported has a solution posted there.<br /><br />                        
            If you do choose to submit a request, please do so via the <a href="<?php 
    echo $jfb_homepage;
    ?>
#feedback" target="_support">plugin homepage</a>, <i><b><u>not</u></b></i> on Wordpress.org (which I rarely check).  Also, please <i><u>specifically mention</u></i> that you've tried it with all other plugins disabled and the default theme (see <a href="<?php 
    echo $jfb_homepage;
    ?>
#faq100" target="_faq100">FAQ100</a>) and include the following information about your Wordpress environment:<br /><br />            
            </div>
            <div class="jfb-greybox">
                Host URL: <b><?php 
    echo $_SERVER["HTTP_HOST"];
    ?>
</b><br />
                Site URL: <b><?php 
    echo get_bloginfo('url');
    ?>
</b><br />
                Wordpress URL: <b><?php 
    echo get_bloginfo('wpurl');
    ?>
</b><br />
            	Wordpress Version: <b><?php 
    echo $GLOBALS['wp_version'];
    ?>
</b><br />
            	BuddyPress Version: <b><?php 
    echo defined('BP_VERSION') ? BP_VERSION : "Not Detected";
    ?>
</b><br />
            	MultiSite Status: <b> <?php 
    echo (defined('WP_ALLOW_MULTISITE') ? "Allowed" : "Off") . " / " . (function_exists('is_multisite') ? is_multisite() ? "Enabled" : "Disabled" : "Undefined");
    ?>
</b><br />
            	Browser Version: <b><?php 
    $browser = jfb_get_browser();
    echo $browser['shortname'] . " " . $browser['version'] . " for " . $browser['platform'];
    ?>
</b><br />
            	Plugin Version: <b><?php 
    echo $jfb_version;
    ?>
</b><br />
    			Addon Version: <b><?php 
    echo defined('JFB_PREMIUM_VER') ? JFB_PREMIUM_VER : "Not Detected";
    ?>
</b><br />
				Facebook API: <b><?php 
    echo class_exists('Facebook') ? "Already present!" : "OK";
    ?>
</b><br />
				Facebook App: <b><?php 
    echo get_option($opt_jfb_app_id) ? get_option($opt_jfb_app_id) : "&lt;Unset&gt;";
    ?>
</b><br/>
				Facebook Reachable: 
                <b><?php 
    $result = jfb_api_get("https://graph.facebook.com/platform");
    if (!$result) {
        echo "NO (Empty Reply)";
    } else {
        if (isset($result['error'])) {
            echo "NO (" . isset($result['error']['message']) ? $result['error']['message'] : "Unknown" . ")";
        } else {
            if (!$result['is_published']) {
                echo "NO (is_published=false)";
            } else {
                echo "OK";
            }
        }
    }
    ?>
</b><br/>
				Facebook Validated: <b><?php 
    echo get_option($opt_jfb_valid) ? "OK" : "NO";
    ?>
</b><br/>
                Theme: <b><?php 
    echo get_current_theme();
    ?>
</b><br />
                Server: <b><?php 
    echo substr($_SERVER['SERVER_SOFTWARE'], 0, 45) . (strlen($_SERVER['SERVER_SOFTWARE']) > 45 ? "..." : "");
    ?>
</b><br />
                Active Plugins: 
                <?php 
    $active_plugins = get_option('active_plugins');
    $plug_info = get_plugins();
    echo "<b>" . count($active_plugins) . "</b><small> (";
    foreach ($active_plugins as $name) {
        echo $plug_info[$name]['Title'] . " " . $plug_info[$name]['Version'] . "; ";
    }
    echo "</small>)<br />";
    ?>
<br />
            </div>
        </div> <!-- End Tab -->
    
    </div><!-- div jfb-admin_wrapper -->  
   </div> <!-- div wrap -->
<?php 
}
Пример #2
0
function jfb_admin_page()
{
    global $jfb_name, $jfb_version;
    global $opt_jfb_app_id, $opt_jfb_api_key, $opt_jfb_api_sec, $opt_jfb_email_to, $opt_jfb_email_logs, $opt_jfb_delay_redir, $jfb_homepage;
    global $opt_jfb_ask_perms, $opt_jfb_mod_done, $opt_jfb_ask_stream, $opt_jfb_stream_content;
    global $opt_jfb_bp_avatars, $opt_jfb_wp_avatars, $opt_jfb_valid, $opt_jfb_fulllogerr, $opt_jfb_disablenonce, $opt_jfb_show_credit;
    global $opt_jfb_username_style, $opt_jfb_hidesponsor;
    ?>
    <div class="wrap">
     <h2><?php 
    echo $jfb_name;
    ?>
 Options</h2>
    <?php 
    //Show applicable warnings (only on this panel's page; global warnings are above)
    if (class_exists('Facebook')) {
        ?>
<div class="error"><p><strong>Warning:</strong> Another plugin has included the Facebook API throughout all of Wordpress.  I suggest you contact that plugin's author and ask them to include it only in pages where it's actually needed.<br /><br />Things may work fine as-is, but *if* the API version included by the other plugin is older than the one required by WP-FB AutoConnect, it's possible that the login process could fail.</p></div><?php 
    }
    if (version_compare('5', PHP_VERSION, ">")) {
        ?>
<div class="error"><p>Sorry, but as of v1.3.0, WP-FB AutoConnect requires PHP5.</p></div><?php 
        die;
    }
    if (function_exists('is_multisite') && is_multisite() && !jfb_premium()) {
        ?>
<div class="error"><p><strong>Warning:</strong> Wordpress MultiSite is only fully supported by the premium version of this plugin; please see <a href="<?php 
        echo $jfb_homepage;
        ?>
#premium"><b>here</b></a> for details.</p></div><?php 
    }
    do_action('wpfb_admin_messages');
    //Which tab to show by default
    $shownTab = get_option($opt_jfb_valid) ? 2 : 1;
    //Update options
    if (isset($_POST['fb_opts_updated'])) {
        //When saving the Facebook options, make sure the key and secret are valid.
        $fbValid = jfb_validate_key($_POST[$opt_jfb_api_key], $_POST[$opt_jfb_api_sec]);
        if ($fbValid && method_exists($fbValid->api_client, 'admin_getAppProperties')) {
            $appInfo = $fbValid->api_client->admin_getAppProperties(array('app_id', 'application_name'));
            if (is_array($appInfo)) {
                $appID = sprintf("%.0f", $appInfo['app_id']);
                $message = '"' . $appInfo['application_name'] . '" (ID ' . $appID . ')';
            } else {
                if ($appInfo->app_id) {
                    //Why does this happen? Presumably because another plugin includes a different version of the API that uses objects instead of arrays
                    $appID = sprintf("%.0f", $appInfo->app_id);
                    $message = '"' . $appInfo->application_name . '" (ID ' . $appID . ')';
                } else {
                    $fbValid = false;
                }
            }
        }
        if ($fbValid) {
            $shownTab = 2;
            update_option($opt_jfb_valid, 1);
            if (get_option($opt_jfb_api_key) != $_POST[$opt_jfb_api_key]) {
                jfb_auth($jfb_name, $jfb_version, 2, "SET: " . $message);
            }
            ?>
<div class="updated"><p><strong>Successfully connected with <?php 
            echo $message;
            ?>
</strong></p></div><?php 
        } else {
            $shownTab = 1;
            update_option($opt_jfb_valid, 0);
            $message = "ERROR: Facebook could not validate your session key and secret!  Are you sure you've entered them correctly?";
            ?>
<div class="updated"><p><?php 
            echo $message;
            ?>
</p></div><?php 
        }
        //We can save these either way, because if "valid" isn't set, a button won't be shown.
        update_option($opt_jfb_app_id, $appID);
        update_option($opt_jfb_api_key, $_POST[$opt_jfb_api_key]);
        update_option($opt_jfb_api_sec, $_POST[$opt_jfb_api_sec]);
    }
    if (isset($_POST['main_opts_updated'])) {
        $shownTab = 2;
        update_option($opt_jfb_ask_perms, $_POST[$opt_jfb_ask_perms]);
        update_option($opt_jfb_ask_stream, $_POST[$opt_jfb_ask_stream]);
        update_option($opt_jfb_wp_avatars, $_POST[$opt_jfb_wp_avatars]);
        update_option($opt_jfb_stream_content, $_POST[$opt_jfb_stream_content]);
        update_option($opt_jfb_show_credit, $_POST[$opt_jfb_show_credit]);
        update_option($opt_jfb_email_to, $_POST[$opt_jfb_email_to]);
        update_option($opt_jfb_email_logs, $_POST[$opt_jfb_email_logs]);
        update_option($opt_jfb_delay_redir, $_POST[$opt_jfb_delay_redir]);
        update_option($opt_jfb_fulllogerr, $_POST[$opt_jfb_fulllogerr]);
        update_option($opt_jfb_disablenonce, $_POST[$opt_jfb_disablenonce]);
        update_option($opt_jfb_username_style, $_POST[$opt_jfb_username_style]);
        ?>
<div class="updated"><p><strong>Options saved.</strong></p></div><?php 
    }
    if (isset($_POST['prem_opts_updated']) && function_exists('jfb_update_premium_opts')) {
        $shownTab = 3;
        jfb_update_premium_opts();
    }
    if (isset($_POST['remove_all_settings'])) {
        $shownTab = 1;
        delete_option($opt_jfb_api_key);
        delete_option($opt_jfb_api_sec);
        delete_option($opt_jfb_email_to);
        delete_option($opt_jfb_email_logs);
        delete_option($opt_jfb_delay_redir);
        delete_option($opt_jfb_ask_perms);
        delete_option($opt_jfb_ask_stream);
        delete_option($opt_jfb_stream_content);
        delete_option($opt_jfb_mod_done);
        delete_option($opt_jfb_valid);
        delete_option($opt_jfb_bp_avatars);
        delete_option($opt_jfb_wp_avatars);
        delete_option($opt_jfb_fulllogerr);
        delete_option($opt_jfb_disablenonce);
        delete_option($opt_jfb_show_credit);
        delete_option($opt_jfb_username_style);
        delete_option($opt_jfb_hidesponsor);
        if (function_exists('jfb_delete_premium_opts')) {
            jfb_delete_premium_opts();
        }
        ?>
<div class="updated"><p><strong><?php 
        _e('All plugin settings have been cleared.');
        ?>
</strong></p></div><?php 
    }
    ?>
    
    <?php 
    if (isset($_REQUEST[$opt_jfb_hidesponsor])) {
        update_option($opt_jfb_hidesponsor, $_REQUEST[$opt_jfb_hidesponsor]);
    }
    if (!get_option($opt_jfb_hidesponsor) && !defined('JFB_PREMIUM')) {
        ?>
      	<!-- Sponsorship message *was* here, until Automattic demanded they be removed from all plugins - see http://gregsplugins.com/lib/2011/11/26/automattic-bullies/ -->
     <?php 
    }
    ?>
     

    <!-- Tab Navigation -->
    <?php 
    //Define some variables that'll be used for our tab-switching
    $allTabsClass = "jfb_admin_tab";
    $allTabBtnsClass = "jfb_admin_tab_btn";
    $tab1Id = "jfb_admin_fbsetup";
    $tab2Id = "jfb_admin_basicoptions";
    $tab3Id = "jfb_admin_premiumoptions";
    $tab4Id = "jfb_admin_uninstall";
    $tab5Id = "jfb_admin_supportinfo";
    ?>
    
    <script type="text/javascript">
        function jfb_swap_tabs(show_tab_id) 
        {
            //Hide all the tabs, then show just the one specified
        	jQuery(".<?php 
    echo $allTabsClass;
    ?>
").hide();
        	jQuery("#" + show_tab_id).show();

        	//Unhighlight all the tab buttons, then highlight just the one specified
        	jQuery(".<?php 
    echo $allTabBtnsClass;
    ?>
").attr("class", "<?php 
    echo $allTabBtnsClass;
    ?>
");
        	jQuery("#" + show_tab_id + "_btn").addClass("jfb-admin_tab_selected");
		}
	</script>
	        
    <div>     
         <ul class="jfb-admin_tabs">
         	<li id="<?php 
    echo $tab1Id;
    ?>
_btn" class="<?php 
    echo $allTabBtnsClass;
    ?>
 <?php 
    echo $shownTab == 1 ? "jfb-admin_tab_selected" : "";
    ?>
"><a href="javascript:void(0);" onclick="jfb_swap_tabs('<?php 
    echo $tab1Id;
    ?>
');">Facebook Setup</a></li>
         	<li id="<?php 
    echo $tab2Id;
    ?>
_btn" class="<?php 
    echo $allTabBtnsClass;
    ?>
 <?php 
    echo $shownTab == 2 ? "jfb-admin_tab_selected" : "";
    ?>
"><a href="javascript:void(0);" onclick="jfb_swap_tabs('<?php 
    echo $tab2Id;
    ?>
')";>Basic Options</a></li>
         	<li id="<?php 
    echo $tab3Id;
    ?>
_btn" class="<?php 
    echo $allTabBtnsClass;
    ?>
 <?php 
    echo $shownTab == 3 ? "jfb-admin_tab_selected" : "";
    ?>
"><a href="javascript:void(0);" onclick="jfb_swap_tabs('<?php 
    echo $tab3Id;
    ?>
');">Premium Options</a></li>
         	<li id="<?php 
    echo $tab4Id;
    ?>
_btn" class="<?php 
    echo $allTabBtnsClass;
    ?>
 <?php 
    echo $shownTab == 4 ? "jfb-admin_tab_selected" : "";
    ?>
"><a href="javascript:void(0);" onclick="jfb_swap_tabs('<?php 
    echo $tab4Id;
    ?>
');">Uninstall</a></li>
         	<li id="<?php 
    echo $tab5Id;
    ?>
_btn" class="<?php 
    echo $allTabBtnsClass;
    ?>
 <?php 
    echo $shownTab == 5 ? "jfb-admin_tab_selected" : "";
    ?>
"><a href="javascript:void(0);" onclick="jfb_swap_tabs('<?php 
    echo $tab5Id;
    ?>
');">Support Info</a></li>
         </ul>
     </div>
     
    <div class="jfb-admin_wrapper">
        <div class="<?php 
    echo $allTabsClass;
    ?>
" id="<?php 
    echo $tab1Id;
    ?>
" style="display:<?php 
    echo $shownTab == 1 ? "block" : "none";
    ?>
">
        	<h3>Setup Instructions</h3>
            To allow your users to login with their Facebook accounts, you must first setup a Facebook Application for your website:<br /><br />
            <ol>
              <li>Visit <a href="http://developers.facebook.com/apps" target="_lnk">developers.facebook.com/apps</a> and click the "Create New App" button.</li>
              <li>Type in a name (i.e. the name of your website) and click "Continue."  This is the name your users will see on the Facebook login popup.</li>
              <li>Facebook may now require you to verify your account before continuing (see <a target="_fbInfo" href="https://developers.facebook.com/blog/post/386/">here</a> for more information).</li>
              <li>Once your app has been created, scroll down and fill in your "Site URL" under "Select how your app integrates with Facebook -&gt;"Website."  Note: http://example.com/ and http://www.example.com/ are <i>not</i> the same.</li>
              <li>Click "Save Changes."</li>
              <li>Copy the App ID and App Secret to the boxes below.</li>
              <li>Click "Save" below.</li>
            </ol>
            <br />That's it!  Now you can add this plugin's <a href="<?php 
    echo admin_url('widgets.php');
    ?>
">sidebar widget</a>, or if you're using BuddyPress, a Facebook button will be automatically added to its built-in login panel.<br /><br />
            For more complete documentation and help, visit the <a href="<?php 
    echo $jfb_homepage;
    ?>
">plugin homepage</a>.<br />
             
            <br />
            <hr />
            
            <h3>Facebook Connect</h3>
            <form name="formFacebook" method="post" action="">
                <input type="text" size="40" name="<?php 
    echo $opt_jfb_api_key;
    ?>
" value="<?php 
    echo get_option($opt_jfb_api_key);
    ?>
" /> App ID<br />
                <input type="text" size="40" name="<?php 
    echo $opt_jfb_api_sec;
    ?>
" value="<?php 
    echo get_option($opt_jfb_api_sec);
    ?>
" /> App Secret
                <input type="hidden" name="fb_opts_updated" value="1" />
                <div class="submit"><input type="submit" name="Submit" value="Connect" /></div>
            </form>
        </div> <!-- End Tab -->
        
        <div class="<?php 
    echo $allTabsClass;
    ?>
" id="<?php 
    echo $tab2Id;
    ?>
" style="display:<?php 
    echo $shownTab == 2 ? "block" : "none";
    ?>
">
            <?php 
    if (!get_option($opt_jfb_valid)) {
        echo "<div class=\"jfb-admin_warning\"><i><b>You must enter a valid APP ID and Secret under the \"Facebook Setup\" tab before this plugin will function.</b></i></div>";
    }
    ?>
            <h3>Basic Options</h3>
            <form name="formMainOptions" method="post" action="">
                <b>Autoregistered Usernames:</b><br />
                <input type="radio" name="<?php 
    echo $opt_jfb_username_style;
    ?>
" value="0" <?php 
    echo get_option($opt_jfb_username_style) == 0 ? "checked='checked'" : "";
    ?>
 >Based on Facebook ID (i.e. FB_123456)<br />
                <input type="radio" name="<?php 
    echo $opt_jfb_username_style;
    ?>
" value="1" <?php 
    echo get_option($opt_jfb_username_style) == 1 ? "checked='checked'" : "";
    ?>
 >Based on real name with prefix (i.e. FB_John_Smith)<br />
                <input type="radio" name="<?php 
    echo $opt_jfb_username_style;
    ?>
" value="3" <?php 
    echo get_option($opt_jfb_username_style) == 3 ? "checked='checked'" : "";
    ?>
 >Based on real name without prefix (i.e. John_Smith) <i><b>(Recommended for BuddyPress)</b></i><br />
                <input type="radio" name="<?php 
    echo $opt_jfb_username_style;
    ?>
" value="2" <?php 
    echo get_option($opt_jfb_username_style) == 2 ? "checked='checked'" : "";
    ?>
 >Legacy Format (i.e. John.Smith) <i><b>(Not Recommended, <dfn title="Although the original 'BuddyPress-friendly' username format included a period, I later learned that this creates issues with author links in Wordpress.  I've left the option here for legacy support, but advise against using it (unless you have only one author on your blog, in which case Facebook-connected users won't have author links and so it doesn't matter).  If you do have multiple authors and are experiencing broken author links, changing this option will fix it for all NEW users, but you may want to consider fixing your existing users by replacing all of the '.'s with '_'s in the 'user_nicename' field of the 'wp_users' database table.">mouseover for why</dfn>)</b></i><br /><br />
            
                <b>E-Mail:</b><br />
                <input type="checkbox" name="<?php 
    echo $opt_jfb_ask_perms;
    ?>
" value="1" <?php 
    echo get_option($opt_jfb_ask_perms) ? 'checked="checked"' : '';
    ?>
 /> Request permission to get the connecting user's email address<br />
        
                <br /><b>Announcement:</b><br />
        		<?php 
    add_option($opt_jfb_stream_content, "has connected to " . get_option('blogname') . " with WP-FB AutoConnect.");
    ?>
        		<input type="checkbox" name="<?php 
    echo $opt_jfb_ask_stream;
    ?>
" value="1" <?php 
    echo get_option($opt_jfb_ask_stream) ? 'checked="checked"' : '';
    ?>
 /> Request permission to post the following announcement on users' Facebook walls when they connect for the first time:<br />
        		<input type="text" size="100" name="<?php 
    echo $opt_jfb_stream_content;
    ?>
" value="<?php 
    echo get_option($opt_jfb_stream_content);
    ?>
" /><br />
        
        		<br /><b>Avatars:</b><br />
                <input type="checkbox" name="<?php 
    echo $opt_jfb_wp_avatars;
    ?>
" value="1" <?php 
    echo get_option($opt_jfb_wp_avatars) ? 'checked="checked"' : '';
    ?>
 /> Use Facebook profile pictures as avatars<br />
        
                <br /><b>Credit:</b><br />
                <input type="checkbox" name="<?php 
    echo $opt_jfb_show_credit;
    ?>
" value="1" <?php 
    echo get_option($opt_jfb_show_credit) ? 'checked="checked"' : '';
    ?>
 /> Display a "Powered By" link in the blog footer (would be appreciated! :))<br />
        
        		<br /><b>Debug:</b><br />
        		<?php 
    add_option($opt_jfb_email_to, get_bloginfo('admin_email'));
    ?>
        		<input type="checkbox" name="<?php 
    echo $opt_jfb_email_logs;
    ?>
" value="1" <?php 
    echo get_option($opt_jfb_email_logs) ? 'checked="checked"' : '';
    ?>
 /> Send all event logs to <input type="text" size="40" name="<?php 
    echo $opt_jfb_email_to;
    ?>
" value="<?php 
    echo get_option($opt_jfb_email_to);
    ?>
" /><br />
        		<input type="checkbox" name="<?php 
    echo $opt_jfb_disablenonce;
    ?>
" value="1" <?php 
    echo get_option($opt_jfb_disablenonce) ? 'checked="checked"' : '';
    ?>
 /> Disable nonce security check (Not recommended)<br />
                <input type="checkbox" name="<?php 
    echo $opt_jfb_delay_redir;
    ?>
" value="1" <?php 
    echo get_option($opt_jfb_delay_redir) ? 'checked="checked"' : '';
    ?>
 /> Delay redirect after login (<i><u>Not for production sites!</u></i>)<br />
                <input type="checkbox" name="<?php 
    echo $opt_jfb_fulllogerr;
    ?>
" value="1" <?php 
    echo get_option($opt_jfb_fulllogerr) ? 'checked="checked"' : '';
    ?>
 /> Show full log on error (<i><u>Not for production sites!</u></i>)<br />
                <input type="hidden" name="main_opts_updated" value="1" />
                <div class="submit"><input type="submit" name="Submit" value="Save" /></div>
            </form>
    	</div><!-- End Tab -->
    
    	<div class="<?php 
    echo $allTabsClass;
    ?>
" id="<?php 
    echo $tab3Id;
    ?>
" style="display:<?php 
    echo $shownTab == 3 ? "block" : "none";
    ?>
">
            <?php 
    if (!get_option($opt_jfb_valid)) {
        echo "<div class=\"jfb-admin_warning\"><i><b>You must enter a valid APP ID and Secret under the \"Facebook Setup\" tab before this plugin will function.</b></i></div>";
    }
    if (function_exists('jfb_output_premium_panel')) {
        jfb_output_premium_panel();
    } else {
        jfb_output_premium_panel_tease();
    }
    ?>
        </div> <!-- End Tab -->
        
        <div class="<?php 
    echo $allTabsClass;
    ?>
" id="<?php 
    echo $tab4Id;
    ?>
" style="display:<?php 
    echo $shownTab == 4 ? "block" : "none";
    ?>
">
            <h3>Delete All Plugin Options</h3>
            The following button will <i>permanently</i> delete all of this plugin's options from your Wordpress database, as if it had never been installed.  Use with care!
            <form name="formDebugOptions" method="post" action="">
                <input type="hidden" name="remove_all_settings" value="1" />
                <div class="submit"><input type="submit" name="Submit" value="Delete" /></div>
            </form>
        </div> <!-- End Tab -->
        
        <div class="<?php 
    echo $allTabsClass;
    ?>
" id="<?php 
    echo $tab5Id;
    ?>
" style="display:<?php 
    echo $shownTab == 5 ? "block" : "none";
    ?>
">
            <h3>Support Information</h3>
            <div style="width:600px;">
            Before submitting a support request, please make sure to carefully read all the documentation and FAQs on the <a href="<?php 
    echo $jfb_homepage;
    ?>
" target="_support">plugin homepage</a>.  Every problem that's ever been reported has a solution posted there.<br /><br />            
            If you're still having trouble, you may submit a request (on the <a href="<?php 
    echo $jfb_homepage;
    ?>
" target="_support">same homepage</a>), but please <i><u>specifically mention</u></i> that you've tried it with all other plugins disabled and the default theme (see <a href="<?php 
    echo $jfb_homepage;
    ?>
#FAQ100">FAQ100</a>).  Also, be sure to include the following information about your Wordpress environment:
            </div>
            <div style="width:600px; padding:5px; margin:2px 0; background-color:#EEEDDA; border:1px solid #CCC;">
            	Wordpress Version: <b><?php 
    echo $GLOBALS['wp_version'];
    ?>
</b><br />
            	BuddyPress Version: <b><?php 
    echo defined('BP_VERSION') ? BP_VERSION : "Not Detected";
    ?>
</b><br />
            	MultiSite Status: <b> <?php 
    echo (defined('WP_ALLOW_MULTISITE') ? "Allowed" : "Not Allowed") . " / " . (function_exists('is_multisite') ? is_multisite() ? "Enabled" : "Disabled" : "Undefined");
    ?>
</b><br />
            	Browser Version: <b><?php 
    $browser = jfb_get_browser();
    echo $browser['shortname'] . " " . $browser['version'] . " for " . $browser['platform'];
    ?>
</b><br />
            	Plugin Version: <b><?php 
    echo $jfb_version;
    ?>
</b><br />
    			Addon Version: <b><?php 
    echo defined('JFB_PREMIUM_VER') ? JFB_PREMIUM_VER : "Not Detected";
    ?>
</b><br />
				Facebook API: <b><?php 
    echo class_exists('Facebook') ? "Already present!" : "OK";
    ?>
</b><br /> 
                Theme: <b><?php 
    echo get_current_theme();
    ?>
</b><br />
                Server: <b><?php 
    echo substr($_SERVER['SERVER_SOFTWARE'], 0, 45) . (strlen($_SERVER['SERVER_SOFTWARE']) > 45 ? "..." : "");
    ?>
</b><br />
                cURL: 
                <?php 
    if (!function_exists('curl_init')) {
        echo "<b>Not installed!</b><br />";
    } else {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/platform');
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/facebook-platform/php-sdk-3.1.1/fb_ca_chain_bundle.crt');
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0');
        $curlcontent = @curl_exec($ch);
        $x = json_decode($curlcontent);
        if ($x->name == "Facebook Developers") {
            echo "<b>OK</b><br />";
        } else {
            echo "<b>Curl is available but cannot access Facebook!</b> (" . curl_errno($ch) . " - " . curl_error($ch) . ")<br />";
        }
        curl_close($ch);
    }
    ?>
                Active Plugins: 
                <?php 
    $active_plugins = get_option('active_plugins');
    $plug_info = get_plugins();
    echo "<b>" . count($active_plugins) . "</b><small> (";
    foreach ($active_plugins as $name) {
        echo $plug_info[$name]['Title'] . " " . $plug_info[$name]['Version'] . "; ";
    }
    echo "</small>)<br />";
    ?>
<br />
            </div>
        </div> <!-- End Tab -->
    
    </div><!-- div jfb-admin_wrapper -->  
   </div> <!-- div wrap -->
<?php 
}