Skip to content

Commit

Permalink
Added wordpress social-connect plugin for google / yahoo / facebook a…
Browse files Browse the repository at this point in the history
…ccount integration.
  • Loading branch information
niflostancu committed Sep 29, 2012
1 parent 319f59f commit b0a439b
Show file tree
Hide file tree
Showing 52 changed files with 5,577 additions and 13 deletions.
2 changes: 1 addition & 1 deletion db/hartapoliticii_mock_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2113,7 +2113,7 @@ INSERT INTO `wp_options` (`option_id`, `blog_id`, `option_name`, `option_value`,
(35, 0, 'hack_file', '', 'yes'),
(36, 0, 'blog_charset', 'UTF-8', 'yes'),
(37, 0, 'moderation_keys', '', 'no'),
(38, 0, 'active_plugins', 'a:3:{i:0;s:19:"akismet/akismet.php";i:1;s:63:"feedburner_feedsmith_plugin_2.3/FeedBurner_FeedSmith_Plugin.php";i:2;s:47:"subscribe-to-comments/subscribe-to-comments.php";}', 'yes'),
(38, 0, 'active_plugins', 'a:4:{i:0;s:19:"akismet/akismet.php";i:1;s:63:"feedburner_feedsmith_plugin_2.3/FeedBurner_FeedSmith_Plugin.php";i:2;s:33:"social-connect/social-connect.php";i:3;s:47:"subscribe-to-comments/subscribe-to-comments.php";}', 'yes'),
(39, 0, 'home', 'http://zen.dev', 'yes'),
(40, 0, 'category_base', '', 'yes'),
(41, 0, 'ping_sites', 'http://rpc.pingomatic.com/', 'yes'),
Expand Down
118 changes: 118 additions & 0 deletions www/wp-content/plugins/social-connect/admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php

function sc_social_connect_admin_menu(){
add_options_page('Social Connect', 'Social Connect', 'manage_options', 'social-connect-id', 'sc_render_social_connect_settings' );
add_action( 'admin_init', 'sc_register_social_connect_settings' );
}
add_action('admin_menu', 'sc_social_connect_admin_menu' );

function sc_register_social_connect_settings(){
register_setting( 'social-connect-settings-group', 'social_connect_facebook_enabled' );
register_setting( 'social-connect-settings-group', 'social_connect_facebook_api_key' );
register_setting( 'social-connect-settings-group', 'social_connect_facebook_secret_key' );

register_setting( 'social-connect-settings-group', 'social_connect_twitter_enabled' );
register_setting( 'social-connect-settings-group', 'social_connect_twitter_consumer_key' );
register_setting( 'social-connect-settings-group', 'social_connect_twitter_consumer_secret' );

register_setting( 'social-connect-settings-group', 'social_connect_google_enabled' );
register_setting( 'social-connect-settings-group', 'social_connect_yahoo_enabled' );
register_setting( 'social-connect-settings-group', 'social_connect_wordpress_enabled' );
}

function sc_render_social_connect_settings(){
?>
<div class="wrap">
<h2><?php _e('Social Connect Settings', 'social_connect'); ?></h2>

<form method="post" action="options.php">
<?php settings_fields( 'social-connect-settings-group' ); ?>
<h3><?php _e('Facebook Settings', 'social_connect'); ?></h3>
<p><?php _e('To connect your site to Facebook, you need a Facebook Application. If you have already created one, please insert your API & Secret key below.', 'social_connect'); ?></p>
<p><?php printf(__('Already registered? Find your keys in your <a target="_blank" href="%2$s">%1$s Application List</a>', 'social_connect'), 'Facebook', 'http://www.facebook.com/developers/apps.php'); ?></li>
<p><?php _e('Need to register?', 'social_connect'); ?></p>
<ol>
<li><?php printf(__('Visit the <a target="_blank" href="%1$s">Facebook Application Setup</a> page', 'social_connect'), 'http://www.facebook.com/developers/createapp.php'); ?></li>
<li><?php printf(__('Get the API information from the <a target="_blank" href="%1$s">Facebook Application List</a>', 'social_connect'), 'http://www.facebook.com/developers/apps.php'); ?></li>
<li><?php _e('Select the application you created, then copy and paste the API key & Application Secret from there.', 'social_connect'); ?></li>
</ol>
<table class="form-table">
<tr valign="top">
<th scope="row"><?php _e('Enable?', 'social_connect'); ?></th>
<td>
<input type="checkbox" name="social_connect_facebook_enabled" value="1" <?php checked(get_option('social_connect_facebook_enabled', 1 ), 1 ); ?> /><br/>
<?php _e('Check this box to enable register/login using Facebook.', 'social_connect'); ?>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('API Key', 'social_connect'); ?></th>
<td><input type="text" name="social_connect_facebook_api_key" value="<?php echo get_option('social_connect_facebook_api_key' ); ?>" /></td>
</tr>

<tr valign="top">
<th scope="row"><?php _e('Secret Key', 'social_connect'); ?></th>
<td><input type="text" name="social_connect_facebook_secret_key" value="<?php echo get_option('social_connect_facebook_secret_key' ); ?>" /></td>
</tr>
</table>

<h3><?php _e('Twitter Settings', 'social_connect'); ?></h3>
<p><?php _e('To offer login via Twitter, you need to register your site as a Twitter Application and get a <strong>Consumer Key</strong>, a <strong>Consumer Secret</strong>, an <strong>Access Token</strong> and an <strong>Access Token Secret</strong>.', 'social_connect'); ?></p>
<p><?php printf(__('Already registered? Find your keys in your <a target="_blank" href="%2$s">%1$s Application List</a>', 'social_connect'), 'Twitter', 'https://dev.twitter.com/apps'); ?></p>
<p><?php printf(__('Need to register? <a href="%1$s">Register an Application</a> and fill the form with the details below:', 'social_connect'), 'http://dev.twitter.com/apps/new'); ?>
<ol>
<li><?php _e('Application Type: <strong>Browser</strong>', 'social_connect'); ?></li>
<li><?php printf(__('Callback URL: <strong>%1$s</strong>', 'social_connect'), SOCIAL_CONNECT_PLUGIN_URL . '/twitter/callback.php'); ?></li>
<li><?php _e('Default Access: <strong>Read &amp; Write</strong>', 'social_connect'); ?></li>
</ol>
<table class="form-table">
<tr valign="top">
<th scope="row"><?php _e('Enable?', 'social_connect'); ?></th>
<td>
<input type="checkbox" name="social_connect_twitter_enabled" value="1" <?php checked(get_option('social_connect_twitter_enabled' ), 1 ); ?> /><br/>
<?php _e('Twitter integration requires the generation of dummy email addresses for authenticating users.<br/>Please check with your domain administrator as this may require changes to your mail server.', 'social_connect'); ?>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Consumer Key', 'social_connect'); ?></th>
<td><input type="text" name="social_connect_twitter_consumer_key" value="<?php echo get_option('social_connect_twitter_consumer_key' ); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Consumer Secret', 'social_connect'); ?></th>
<td><input type="text" name="social_connect_twitter_consumer_secret" value="<?php echo get_option('social_connect_twitter_consumer_secret' ); ?>" /></td>
</tr>
</table>

<h3><?php _e('OpenID Providers', 'social_connect'); ?></h3>
<p><?php _e('Choose the OpenID providers your visitors can use to register, comment and login.', 'social_connect'); ?></p>
<table class="form-table">
<tr valign="top">
<th scope="row">Google</th>
<td>
<input type="checkbox" name="social_connect_google_enabled" value="1" <?php checked(get_option('social_connect_google_enabled', 1 ), 1 ); ?> />
</td>
</tr>
<tr valign="top">
<th scope="row">Yahoo</th>
<td>
<input type="checkbox" name="social_connect_yahoo_enabled" value="1" <?php checked(get_option('social_connect_yahoo_enabled', 1 ), 1 ); ?> />
</td>
</tr>
<tr valign="top">
<th scope="row">WordPress.com</th>
<td>
<input type="checkbox" name="social_connect_wordpress_enabled" value="1" <?php checked(get_option('social_connect_wordpress_enabled', 1 ), 1 ); ?> />
</td>
</tr>
</table>

<p class="submit">
<input type="submit" class="button-primary" value="<?php _e('Save Changes' ) ?>" />
</p>

<h2><?php _e('Rewrite Diagnostics', 'social_connect'); ?></h2>
<p><?php _e('Click on the link below to confirm your URL rewriting and query string parameter passing are setup correctly on your server. If you see a "Test was successful" message after clicking the link then you are good to go. If you see a 404 error or some other error then you need to update rewrite rules or ask your service provider to configure your server settings such that the below URL works correctly.', 'social_connect'); ?></p>
<p><a class="button-primary" href='<?php echo SOCIAL_CONNECT_PLUGIN_URL ?>/diagnostics/test.php?testing=http://www.example.com' target='_blank'><?php _e('Test server redirection settings', 'social_connect'); ?></a></p>
<p>If you web server fails this test, please have your hosting provider whitelist your domain on <em>mod_security</em>. Learn more on the <a href="http://wordpress.org/extend/plugins/social-connect/faq/">Social Connect FAQ</a>.
</form>
</div> <?php
}
8 changes: 8 additions & 0 deletions www/wp-content/plugins/social-connect/constants.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
require_once( dirname( dirname( dirname( dirname( __FILE__ )))) . '/wp-load.php' );

if( !defined( 'SOCIAL_CONNECT_PLUGIN_URL' )) {
define( 'SOCIAL_CONNECT_PLUGIN_URL', plugins_url() . '/' . basename( dirname( __FILE__ )));
}

?>
26 changes: 26 additions & 0 deletions www/wp-content/plugins/social-connect/diagnostics/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
require_once( dirname( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) ) . '/wp-load.php' );

$testing = "";
$msg = "";
$testing = $_REQUEST['testing'];
if ( $testing == "http://www.example.com" ) {
$msg = __( 'Test was successful! <br/><br/> The rewrite rules on your server appear to be setup correctly for Social Connect to work.', 'social_connect' );
} else {
$msg = sprintf( __( 'Test was unsuccessful. Expected "http://www.example.com", received "%s".', 'social_connect' ), $testing );
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
<div class="wrap">
<h2><?php _e( 'Social Connect Diagnostics', 'social_connect' ); ?></h2>
<p><?php echo $msg; ?></p>
</div>
</body>
</html>


41 changes: 41 additions & 0 deletions www/wp-content/plugins/social-connect/facebook/callback.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
require_once(dirname(dirname(__FILE__)) . '/constants.php' );
require_once(dirname(__FILE__) . '/facebook.php' );
require_once(dirname(dirname(__FILE__)) . '/utils.php' );

$client_id = get_option('social_connect_facebook_api_key');
$secret_key = get_option('social_connect_facebook_secret_key');

if(isset($_GET['code'])) {
$code = $_GET['code'];
$client_id = get_option('social_connect_facebook_api_key');
$secret_key = get_option('social_connect_facebook_secret_key');
parse_str(sc_curl_get_contents("https://graph.facebook.com/oauth/access_token?" .
'client_id=' . $client_id . '&redirect_uri=' . urlencode(SOCIAL_CONNECT_PLUGIN_URL . '/facebook/callback.php') .
'&client_secret=' . $secret_key .
'&code=' . urlencode($code)));

$signature = social_connect_generate_signature($access_token);
?>
<html>
<head>
<script>
function init() {
window.opener.wp_social_connect({'action' : 'social_connect', 'social_connect_provider' : 'facebook',
'social_connect_signature' : '<?php echo $signature ?>',
'social_connect_access_token' : '<?php echo $access_token ?>'});

window.close();
}
</script>
</head>
<body onload="init();">
</body>
</html>
<?php

} else {
$redirect_uri = urlencode(SOCIAL_CONNECT_PLUGIN_URL . '/facebook/callback.php');
wp_redirect('https://graph.facebook.com/oauth/authorize?client_id=' . $client_id . '&redirect_uri=' . $redirect_uri . '&scope=email');
}
?>
Loading

0 comments on commit b0a439b

Please sign in to comment.