Social Login - Version 1.0

Version Description

  • Initial release.
Download this release

Release Info

Developer ClaudeSchlesser
Plugin Icon 128x128 Social Login
Version 1.0
Comparing to
See all releases

Version 1.0

assets/css/admin.css ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .oa_container {
2
+ border: 1px solid #ccc;
3
+ padding: 10px;
4
+ clear: both;
5
+ margin-bottom: 10px;
6
+ overflow: hidden;
7
+ width: 628px;
8
+ }
9
+
10
+ .oa_container.oa_container_welcome {
11
+ background-color: #E1EDFF
12
+ }
13
+
14
+ .oa_container .oa_container_title {
15
+ border-bottom: 1px solid #A8A8A8;
16
+ clear: both;
17
+ color: #000000;
18
+ font-size: 16px;
19
+ font-weight: bold;
20
+ line-height: 26px;
21
+ margin: 0 0 10px;
22
+ padding-bottom: 5px;
23
+ }
24
+
25
+ .oa_form_table {
26
+ background-color: #efefef;
27
+ border: 1px solid #ccc;
28
+ width: 650px;
29
+ margin-bottom: 10px;
30
+ }
31
+
32
+ .oa_form_table .head {
33
+ font-weight: bold;
34
+ font-size: 13px;
35
+ font-weight: bold;
36
+ background-color: #ddd;
37
+ }
38
+
39
+ .oa_form_table .foot td {
40
+ height: 40px;
41
+ background-color: #ddd;
42
+ text-align: center;
43
+ }
44
+
45
+ .oa_form_table .foot .error_message{
46
+ color:red;
47
+ font-weight:bold;
48
+ }
49
+
50
+ .oa_form_table .foot .success_message{
51
+ color:green;
52
+ font-weight:bold;
53
+ }
54
+
55
+ .oa_form_table .row_even {
56
+ background-color: #fff;
57
+ }
58
+
59
+ .oa_form_table .row_provider {
60
+ line-height: 35px;
61
+ }
62
+
63
+ .oa_form_table .row_provider .oa_provider {
64
+ margin: 0 10px 0 0
65
+ }
66
+
67
+ .oa_provider {
68
+ background-image: url("../img/provider_sprite_35_35.png");
69
+ text-indent: -9999px;
70
+ height: 35px;
71
+ width: 35px;
72
+ display: inline-block;
73
+ }
74
+
75
+ .oa_provider.oa_provider_aol {
76
+ background-position: -2px -1px;
77
+ }
78
+
79
+ .oa_provider.oa_provider_blogger {
80
+ background-position: -39px -1px;
81
+ }
82
+
83
+ .oa_provider.oa_provider_facebook {
84
+ background-position: -76px -1px;
85
+ }
86
+
87
+ .oa_provider.oa_provider_foursquare {
88
+ background-position: 629px -1px;
89
+ }
90
+
91
+ .oa_provider.oa_provider_google {
92
+ background-position: 592px -1px;
93
+ }
94
+
95
+ .oa_provider.oa_provider_hyves {
96
+ background-position: 555px -1px;
97
+ }
98
+
99
+ .oa_provider.oa_provider_linkedin {
100
+ background-position: 518px -1px;
101
+ }
102
+
103
+ .oa_provider.oa_provider_livejournal {
104
+ background-position: 444px -1px;
105
+ }
106
+
107
+ .oa_provider.oa_provider_myspace {
108
+ background-position: 370px -1px;
109
+ }
110
+
111
+ .oa_provider.oa_provider_twitter {
112
+ background-position: 222px -1px;
113
+ }
114
+
115
+ .oa_provider.oa_provider_yahoo {
116
+ background-position: 37px -1px;
117
+ }
118
+
119
+ .oa_provider.oa_provider_openid {
120
+ background-position: 333px -1px;
121
+ }
122
+
123
+ .oa_provider.oa_provider_wordpress {
124
+ background-position: 74px -1px;
125
+ }
126
+
127
+ .oa_provider.oa_provider_vkontakte {
128
+ background-position: 111px -1px;
129
+ }
assets/img/provider_sprite_35_35.png ADDED
Binary file
assets/js/admin.js ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function($) {
2
+
3
+
4
+ $('#oa_social_login_test_api_settings').click(function(){
5
+ var subdomain = jQuery('#oa_social_login_settings_api_subdomain').val();
6
+ var key = jQuery('#oa_social_login_settings_api_key').val();
7
+ var secret = jQuery('#oa_social_login_settings_api_secret').val();
8
+
9
+ var data = {
10
+ _ajax_nonce: oa_social_login_ajax_nonce.value,
11
+ action: 'check_api_settings',
12
+ api_subdomain: subdomain,
13
+ api_key: key,
14
+ api_secret: secret
15
+ };
16
+
17
+ jQuery.post(ajaxurl,data, function(response) {
18
+ var message;
19
+ var success;
20
+
21
+
22
+ if (response == 'error_subdomain_wrong'){
23
+ success = false;
24
+ message = 'The subdomain does not exist. Have you filled it out correctly?'
25
+ }
26
+ else if (response == 'error_authentication_credentials_wrong'){
27
+ success = false;
28
+ message = 'The API credentials are wrong';
29
+ }
30
+ else {
31
+ success = true;
32
+ message = 'The API Settings are correct!';
33
+ }
34
+
35
+ jQuery('#oa_social_login_api_test_result').html(message);
36
+
37
+ if (success){
38
+ jQuery('#oa_social_login_api_test_result').removeClass('error_message');
39
+ jQuery('#oa_social_login_api_test_result').addClass('success_message');
40
+ } else {
41
+ jQuery('#oa_social_login_api_test_result').removeClass('success_message');
42
+ jQuery('#oa_social_login_api_test_result').addClass('error_message');
43
+ }
44
+
45
+ });
46
+ return false;
47
+ });
48
+ });
includes/admin.php ADDED
@@ -0,0 +1,317 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Add Settings Tab
5
+ **/
6
+ function oa_social_login_admin_menu ()
7
+ {
8
+ $page = add_options_page ('Social Login', 'Social Login', 'manage_options', 'oa_social_login', 'oa_display_social_login_settings');
9
+ add_action ('admin_print_styles-' . $page, 'oa_social_login_admin_css');
10
+ add_action ('admin_enqueue_scripts', 'oa_social_login_admin_js');
11
+ add_action ('admin_init', 'oa_register_social_login_settings');
12
+ add_action ('admin_notices', 'oa_social_login_admin_message');
13
+ }
14
+ add_action ('admin_menu', 'oa_social_login_admin_menu');
15
+
16
+
17
+ /**
18
+ * Add an activation message to be displayed once
19
+ */
20
+ function oa_social_login_admin_message ()
21
+ {
22
+ if (get_option('oa_social_login_activation_message') !== '1')
23
+ {
24
+ echo '<div class="updated"><p><strong>Thank you for using the Social Login Plugin!</strong> Please go to the <strong>Settings\Social Login</strong> page to setup the plugin.</p></div>';
25
+ update_option ('oa_social_login_activation_message', '1');
26
+ }
27
+ }
28
+
29
+ /**
30
+ * Check API Settings trough an Ajax Call
31
+ */
32
+ function oa_social_login_check_api_settings()
33
+ {
34
+ check_ajax_referer('oa_social_login_ajax_nonce');
35
+
36
+ $api_domain = $_POST['api_subdomain'].'.api.oneall.com';
37
+ $api_key = $_POST['api_key'];
38
+ $api_secret = $_POST['api_secret'];
39
+
40
+ $curl = curl_init();
41
+ curl_setopt($curl, CURLOPT_URL, 'https://'.$api_domain.'/tools/ping.json');
42
+ curl_setopt($curl, CURLOPT_HEADER, 0);
43
+ curl_setopt($curl, CURLOPT_USERPWD, $api_key . ":" . $api_secret);
44
+ curl_setopt($curl, CURLOPT_TIMEOUT, 5);
45
+ curl_setopt($curl, CURLOPT_VERBOSE, 0);
46
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
47
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
48
+ curl_setopt($curl, CURLOPT_FAILONERROR, 0);
49
+ if ( ($json = curl_exec($curl)) === false)
50
+ {
51
+ echo 'Curl error: ' . curl_error($curl);
52
+ }
53
+ //Success
54
+ else
55
+ {
56
+ $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
57
+
58
+ //Authentication Error
59
+ if ($http_code == 401)
60
+ {
61
+ echo 'error_authentication_credentials_wrong';
62
+ delete_option ('oa_social_login_api_settings_verified');
63
+ }
64
+ elseif ($http_code == 404)
65
+ {
66
+ echo 'error_subdomain_wrong';
67
+ delete_option ('oa_social_login_api_settings_verified');
68
+ }
69
+ elseif ($http_code == 200)
70
+ {
71
+ echo 'success';
72
+ update_option ('oa_social_login_api_settings_verified', '1');
73
+ }
74
+ }
75
+
76
+ die();
77
+ }
78
+ add_action('wp_ajax_check_api_settings', 'oa_social_login_check_api_settings');
79
+
80
+
81
+ /**
82
+ * Add Settings JS
83
+ **/
84
+ function oa_social_login_admin_js ($hook)
85
+ {
86
+ if ($hook == 'settings_page_oa_social_login')
87
+ {
88
+ if (!wp_script_is ('oa_social_login_admin_js', 'registered'))
89
+ {
90
+ wp_register_script('oa_social_login_admin_js', OA_SOCIAL_LOGIN_PLUGIN_URL . "/assets/js/admin.js");
91
+ }
92
+
93
+ wp_enqueue_script ('oa_social_login_admin_js');
94
+ wp_enqueue_script ('jquery');
95
+
96
+ $oa_social_login_ajax_nonce = wp_create_nonce ('oa_social_login_ajax_nonce');
97
+ wp_localize_script('oa_social_login_admin_js', 'oa_social_login_ajax_nonce', array ('value' => $oa_social_login_ajax_nonce));
98
+ }
99
+ }
100
+
101
+ /**
102
+ * Add Settings CSS
103
+ **/
104
+ function oa_social_login_admin_css ($hook)
105
+ {
106
+ if (!wp_style_is ('oa_social_login_admin_css', 'registered'))
107
+ {
108
+ wp_register_style ('oa_social_login_admin_css', OA_SOCIAL_LOGIN_PLUGIN_URL . "/assets/css/admin.css");
109
+ }
110
+
111
+ if (did_action ('wp_print_styles'))
112
+ {
113
+ wp_print_styles ('oa_social_login_admin_css');
114
+ }
115
+ else
116
+ {
117
+ wp_enqueue_style ('oa_social_login_admin_css');
118
+ }
119
+ }
120
+
121
+
122
+ /**
123
+ * Register plugin settings and their sanitization callback
124
+ */
125
+ function oa_register_social_login_settings ()
126
+ {
127
+ register_setting ('oa_social_login_settings_group', 'oa_social_login_settings', 'oa_social_login_settings_validate');
128
+ }
129
+
130
+
131
+ /**
132
+ * Plugin settings sanitization callback
133
+ */
134
+ function oa_social_login_settings_validate ($settings)
135
+ {
136
+ //Import providers
137
+ GLOBAL $oa_social_login_providers;
138
+
139
+ //Sanitzed Settings
140
+ $sanitzed_settings = array ();
141
+
142
+ //Base Settings
143
+ foreach (array (
144
+ 'api_subdomain',
145
+ 'api_key',
146
+ 'api_secret',
147
+ 'plugin_caption'
148
+ ) AS $key)
149
+ {
150
+ if (isset ($settings [$key]))
151
+ {
152
+ $sanitzed_settings [$key] = trim ($settings [$key]);
153
+ }
154
+ }
155
+
156
+ //Enabled providers
157
+ if (isset ($settings ['providers']) AND is_array ($settings ['providers']))
158
+ {
159
+ foreach ($oa_social_login_providers AS $key => $name)
160
+ {
161
+ if (isset ($settings ['providers'] [$key]) AND $settings ['providers'] [$key] == '1')
162
+ {
163
+ $sanitzed_settings ['providers'] [$key] = 1;
164
+ }
165
+ }
166
+ }
167
+
168
+ //Done
169
+ return $sanitzed_settings;
170
+ }
171
+
172
+
173
+ /**
174
+ * Display Settings Page
175
+ **/
176
+ function oa_display_social_login_settings ()
177
+ {
178
+ //Import providers
179
+ GLOBAL $oa_social_login_providers;
180
+ ?>
181
+ <div class="wrap">
182
+ <h2><?php _e ('Social Login Settings', 'oa_social_login'); ?></h2>
183
+ <?php
184
+ if (get_option('oa_social_login_api_settings_verified') !== '1')
185
+ {
186
+ ?>
187
+ <div class="oa_container oa_container_welcome">
188
+ <h3>
189
+ Make your blog social!
190
+ </h3>
191
+ <div class="oa_container_body">
192
+ <p>
193
+ Allow your visitors to comment, login and register with social networks like Twitter, Facebook, LinkedIn, Hyves, Вконтакте, Google or Yahoo.
194
+ <strong>Draw a larger audience and increase user engagement in a few simple steps.</strong>
195
+ </p>
196
+ <p>
197
+ To be able to use this plugin you first of all need to create a free account at <a href="https://app.oneall.com/signup/" target="_blank">http://www.oneall.com</a>
198
+ and create a new Site. After having created your account and setup your Site, please enter the Site Settings in the form below.
199
+ </p>
200
+ <h3>The basic account creation is free and the setup is easy!</h3>
201
+ <p>
202
+ <a class="button-secondary" href="https://app.oneall.com/signup/" target="_blank"><strong>Setup my account now</strong></a>
203
+ </p>
204
+ </div>
205
+ </div>
206
+ <?php
207
+ }
208
+ else
209
+ {
210
+ ?>
211
+ <div class="oa_container oa_container_welcome">
212
+ <h3>
213
+ Your API Account is setup correctly
214
+ </h3>
215
+ <div class="oa_container_body">
216
+ <p>
217
+ Login to your account to manage your providers and access your <a href="http://www.oneall.com/services/social-insights/" target="_blank">Social Insights</a>.
218
+ Determine which social networks are popular amongst your users and tailor your registration experience increase user engagement
219
+ </p>
220
+ <p>
221
+ <a class="button-secondary" href="https://app.oneall.com/signin/" target="_blank"><strong>Signin to my account</strong></a>
222
+ </p>
223
+ </div>
224
+ </div>
225
+ <?php
226
+ }
227
+ ?>
228
+ <form method="post" action="options.php">
229
+ <?php
230
+ settings_fields ('oa_social_login_settings_group');
231
+ $settings = get_option ('oa_social_login_settings');
232
+ ?>
233
+ <table class="form-table oa_form_table">
234
+ <tr>
235
+ <th class="head" colspan="2">
236
+ <?php _e('API Settings', 'oa_social_login'); ?>
237
+ </th>
238
+ </tr>
239
+ <tr>
240
+ <th scope="row">
241
+ <label for="oneall_api_subdomain"><?php _e('API Subdomain', 'oa_social_login'); ?>:</label>
242
+ </th>
243
+ <td>
244
+ <input type="text" id="oa_social_login_settings_api_subdomain" name="oa_social_login_settings[api_subdomain]" size="60" value="<?php echo (isset ($settings ['api_subdomain']) ? htmlspecialchars ($settings ['api_subdomain']) : ''); ?>" />
245
+ </td>
246
+ </tr>
247
+ <tr>
248
+ <th scope="row">
249
+ <label for="oneall_api_public_key"><?php _e('API Public Key', 'oa_social_login'); ?>:</label>
250
+ </th>
251
+ <td>
252
+ <input type="text" id="oa_social_login_settings_api_key" name="oa_social_login_settings[api_key]" size="60" value="<?php echo (isset ($settings ['api_key']) ? htmlspecialchars ($settings ['api_key']) : ''); ?>" />
253
+ </td>
254
+ </tr>
255
+ <tr>
256
+ <th scope="row">
257
+ <label for="oneall_api_private_key"><?php _e('API Private Key', 'oa_social_login'); ?>:</label>
258
+ </th>
259
+ <td>
260
+ <input type="text" id="oa_social_login_settings_api_secret" name="oa_social_login_settings[api_secret]" size="60" value="<?php echo (isset ($settings ['api_secret']) ? htmlspecialchars ($settings ['api_secret']) : ''); ?>" />
261
+ </td>
262
+ </tr>
263
+ <tr class="foot">
264
+ <td>
265
+ <a class="button-secondary" id="oa_social_login_test_api_settings" href="#"><?php _e('Verify API Settings', 'oa_social_login'); ?></a>
266
+ </td>
267
+ <td>
268
+ <div id="oa_social_login_api_test_result"></div>
269
+ </td>
270
+ </tr>
271
+ </table>
272
+
273
+ <table class="form-table oa_form_table">
274
+ <tr>
275
+ <th class="head" colspan="2">
276
+ Enable the providers of your choice
277
+ </th>
278
+ </tr>
279
+ <?php
280
+ $i = 0;
281
+ foreach ($oa_social_login_providers AS $key => $name)
282
+ {
283
+ ?>
284
+ <tr class="<?php echo ((($i++) % 2) == 0) ? 'row_even' : 'row_odd)' ?> row_provider">
285
+ <th scope="row">
286
+ <label for="oneall_social_login_provider_<?php echo $key; ?>"><span class="oa_provider oa_provider_<?php echo $key; ?>" title="<?php echo htmlspecialchars ($name); ?>"><?php echo htmlspecialchars ($name); ?></span></label>
287
+ <input type="checkbox" id="oneall_social_login_provider_<?php echo $key; ?>" name="oa_social_login_settings[providers][<?php echo $key; ?>]" value="1" <?php checked ('1', $settings ['providers'] [$key]); ?> />
288
+ <label for="oneall_social_login_provider_<?php echo $key; ?>"><?php echo htmlspecialchars ($name); ?></label>
289
+ </th>
290
+ </tr>
291
+ <?php
292
+ }
293
+ ?>
294
+ </table>
295
+
296
+ <table class="form-table oa_form_table">
297
+ <tr>
298
+ <th class="head" colspan="2">
299
+ <?php _e('Settings', 'oa_social_login'); ?>
300
+ </th>
301
+ </tr>
302
+ <tr>
303
+ <th scope="row">
304
+ <label for="oneall_api_private_key"><?php _e('Social Login Caption', 'oa_social_login'); ?>:</label>
305
+ </th>
306
+ <td>
307
+ <input type="text" id="oa_social_login_settings_plugin_caption" name="oa_social_login_settings[plugin_caption]" size="60" value="<?php echo (isset ($settings ['plugin_caption']) ? htmlspecialchars ($settings ['plugin_caption']) : _e('Connect with:')); ?>" />
308
+ </td>
309
+ </tr>
310
+ </table>
311
+ <p class="submit">
312
+ <input type="submit" class="button-primary" value="<?php _e ('Save Changes') ?>" />
313
+ </p>
314
+ </form>
315
+ </div>
316
+ <?php
317
+ }
includes/settings.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Providers that are currently enabled
4
+ */
5
+ $oa_social_login_providers = array (
6
+ 'facebook' => 'Facebook',
7
+ 'twitter' => 'Twitter',
8
+ 'google' => 'Google',
9
+ 'linkedin' => 'LinkedIn',
10
+ 'yahoo' => 'Yahoo',
11
+ 'openid' => 'OpenID',
12
+ 'wordpress' => 'Wordpress.com',
13
+ 'hyves' => 'Hyves',
14
+ 'vkontakte' => 'VKontakte (Вконтакте)'
15
+ );
16
+
includes/toolbox.php ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once(dirname (dirname (dirname (dirname (dirname (__FILE__))))) . '/wp-load.php');
3
+
4
+
5
+ /**
6
+ * Get the user details for a specific token
7
+ */
8
+ function oa_social_login_get_user_by_token ($user_token)
9
+ {
10
+ global $wpdb;
11
+ $sql = "SELECT u.ID FROM $wpdb->usermeta AS um INNER JOIN $wpdb->users AS u ON (um.user_id=u.ID) WHERE um.meta_key = 'oa_social_login_user_token' AND um.meta_value = '%s'";
12
+ return $wpdb->get_var ($wpdb->prepare ($sql, $user_token));
13
+ }
14
+
15
+
16
+ /**
17
+ * Handle the callback
18
+ */
19
+ function oa_social_login_callback ()
20
+ {
21
+ //Callback Handler
22
+ if (isset ($_POST) AND !empty ($_POST ['oa_action']) AND $_POST ['oa_action'] == 'social_login' AND !empty ($_POST ['connection_token']))
23
+ {
24
+ //Read settings
25
+ $settings = get_option ('oa_social_login_settings');
26
+
27
+ //API Settings
28
+ $api_subdomain = (!empty ($settings ['api_subdomain']) ? $settings ['api_subdomain'] : '');
29
+ $api_key = (!empty ($settings ['api_key']) ? $settings ['api_key'] : '');
30
+ $api_secret = (!empty ($settings ['api_secret']) ? $settings ['api_secret'] : '');
31
+
32
+ //Get user profile
33
+ $curl = curl_init ();
34
+ curl_setopt ($curl, CURLOPT_URL, 'https://' . $api_subdomain . '.api.oneall.com/connections/' . $_POST ['connection_token'] . '.json');
35
+ curl_setopt ($curl, CURLOPT_HEADER, 0);
36
+ curl_setopt ($curl, CURLOPT_USERPWD, $api_key . ":" . $api_secret);
37
+ curl_setopt ($curl, CURLOPT_TIMEOUT, 15);
38
+ curl_setopt ($curl, CURLOPT_VERBOSE, 0);
39
+ curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
40
+ curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
41
+ curl_setopt ($curl, CURLOPT_FAILONERROR, 0);
42
+
43
+ //Process
44
+ if (($json = curl_exec ($curl)) !== false)
45
+ {
46
+ //Close connection
47
+ curl_close ($curl);
48
+
49
+ //Decode
50
+ $social_data = json_decode ($json);
51
+
52
+ //User Data
53
+ if (is_object ($social_data) AND $social_data->response->result->status->code == 200)
54
+ {
55
+
56
+ $identity = $social_data->response->result->data->user->identity;
57
+ $user_token = $social_data->response->result->data->user->user_token;
58
+
59
+ //Identity
60
+ $user_identity_id = $identity->id;
61
+ $user_identity_provider = $identity->source->name;
62
+
63
+ //Firstname
64
+ $user_first_name = $identity->name->givenName;
65
+
66
+ //Lastname
67
+ $user_last_name = $identity->name->familyName;
68
+
69
+ //Fullname
70
+ if ( ! empty ($identity->name->formatted))
71
+ {
72
+ $user_full_name = $identity->name->formatted;
73
+ }
74
+ elseif ( ! empty ($identity->name->displayName))
75
+ {
76
+ $user_full_name = $identity->name->displayName;
77
+ }
78
+ else
79
+ {
80
+ $user_full_name = trim ($user_first_name.' '.$user_last_name);
81
+ }
82
+
83
+ //Email
84
+ $user_email = '';
85
+ if (property_exists ($identity, 'emails') AND is_array ($identity->emails))
86
+ {
87
+ foreach ($identity->emails AS $email)
88
+ {
89
+ $user_email = $email->value;
90
+ }
91
+ }
92
+ //User Website
93
+ if ( ! empty ($identity->profileUrl))
94
+ {
95
+ $user_website = $identity->profileUrl;
96
+ }
97
+ elseif ( ! empty ($identity->urls [0]->value))
98
+ {
99
+ $user_website = $identity->urls [0]->value;
100
+ }
101
+ else
102
+ {
103
+ $user_website = '';
104
+ }
105
+
106
+ //Preferred Username
107
+ if ( ! empty ($identity->preferredUsername))
108
+ {
109
+ $user_login = $identity->preferredUsername;
110
+ }
111
+ elseif (! empty ($identity->displayName))
112
+ {
113
+ $user_login = $identity->displayName;
114
+ }
115
+ elseif (! empty ($identity->name->formatted))
116
+ {
117
+ $user_login = $identity->name->formatted;
118
+ }
119
+ else
120
+ {
121
+ $user_login = 'user_' . rand (99999, 999999);
122
+ }
123
+
124
+ // Get user by token
125
+ $user_id = oa_social_login_get_user_by_token ($user_token);
126
+
127
+ //User found
128
+ if ($user_id)
129
+ {
130
+ $user_data = get_userdata ($user_id);
131
+ $user_login = $user_data->user_login;
132
+ }
133
+ else
134
+ {
135
+ // Create new user and associate token
136
+ $user_login_raw = $user_login;
137
+ $i = 1;
138
+ while (username_exists ($user_login))
139
+ {
140
+ $user_login = $user_login_raw . '-'.($i++);
141
+ }
142
+
143
+ $userdata = array (
144
+ 'user_login' => $user_login,
145
+ 'user_email' => $user_email,
146
+ 'first_name' => $user_first_name,
147
+ 'last_name' => $user_last_name,
148
+ 'user_url' => $user_website,
149
+ 'user_pass' => wp_generate_password ()
150
+ );
151
+
152
+ // Create a new user
153
+ $user_id = wp_insert_user ($userdata);
154
+ if ( ! empty ($user_id))
155
+ {
156
+ delete_metadata('user', null, 'oa_social_login_user_token', $user_token, true);
157
+ update_user_meta ($user_id, 'oa_social_login_user_token', $user_token);
158
+ update_user_meta ($user_id, 'oa_social_login_identity_id', $user_identity_id);
159
+ update_user_meta ($user_id, 'oa_social_login_identity_provider', $user_identity_provider);
160
+ }
161
+ }
162
+
163
+ wp_set_auth_cookie ($user_id);
164
+ wp_set_current_user($user_id);
165
+ }
166
+ }
167
+ }
168
+ }
169
+
includes/user_interface.php ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Include the Social Library
5
+ **/
6
+ function oa_social_login_add_javascripts ()
7
+ {
8
+ if ( ! wp_script_is ('oa_social_library', 'registered'))
9
+ {
10
+ //Read settings
11
+ $settings = get_option ('oa_social_login_settings');
12
+
13
+ if (!empty ($settings ['api_subdomain']))
14
+ {
15
+ wp_register_script ("oa_social_library", (is_ssl() ? 'https' : 'http').'://'.$settings ['api_subdomain'].'.api.oneall.com/socialize/library.js');
16
+ }
17
+ }
18
+ wp_print_scripts ("oa_social_library");
19
+ }
20
+ add_action ('login_head', 'oa_social_login_add_javascripts');
21
+ add_action ('wp_head', 'oa_social_login_add_javascripts');
22
+
23
+
24
+
25
+ /**
26
+ * Setup Shortcode handler
27
+ **/
28
+ function oa_social_login_shortcode_handler ($args)
29
+ {
30
+ if (!is_user_logged_in ())
31
+ {
32
+ oa_social_login_render_login_form ();
33
+ }
34
+ }
35
+ add_shortcode ('oa_social_login', 'oa_social_login_shortcode_handler');
36
+
37
+
38
+
39
+ /**
40
+ * Display the provider grid for comments
41
+ */
42
+ function oa_social_login_render_login_form_comments ()
43
+ {
44
+ if (comments_open () && !is_user_logged_in ())
45
+ {
46
+ oa_social_login_render_login_form ();
47
+ }
48
+ }
49
+ add_action ('comment_form_top', 'oa_social_login_render_login_form_comments');
50
+
51
+
52
+
53
+ /**
54
+ * Display the provider grid for registration
55
+ */
56
+ function oa_social_login_render_login_form_registration ()
57
+ {
58
+ if (get_option('users_can_register') === '1')
59
+ {
60
+ oa_social_login_render_login_form ();
61
+ }
62
+ }
63
+ add_action ('register_form', 'oa_social_login_render_login_form_registration');
64
+
65
+
66
+
67
+ /**
68
+ * Display the provider grid for login
69
+ */
70
+ function oa_social_login_render_login_form_login ()
71
+ {
72
+ oa_social_login_render_login_form ();
73
+ }
74
+ add_action ('login_form', 'oa_social_login_render_login_form_login');
75
+
76
+
77
+ /**
78
+ * Display the provider grid
79
+ */
80
+ function oa_social_login_render_login_form ($args = null)
81
+ {
82
+ //Import providers
83
+ GLOBAL $oa_social_login_providers;
84
+
85
+ //Arguments
86
+ $target = 'inline';
87
+ if (is_array ($args))
88
+ {
89
+ if (isset ($args['target']))
90
+ {
91
+ if ($args['target'] == 'widget')
92
+ {
93
+ $target = 'widget';
94
+ }
95
+ }
96
+ }
97
+
98
+ //Read settings
99
+ $settings = get_option ('oa_social_login_settings');
100
+
101
+ //API Subdomain
102
+ $api_subdomain = (!empty ($settings ['api_subdomain']) ? $settings ['api_subdomain'] : '');
103
+
104
+ //API Subdomain Required
105
+ if ( ! empty ($api_subdomain))
106
+ {
107
+ //Caption
108
+ $plugin_caption = (!empty ($settings ['plugin_caption']) ? $settings ['plugin_caption'] : '');
109
+
110
+ //Build providers
111
+ $providers = array ();
112
+ if (is_array ($settings ['providers']))
113
+ {
114
+ foreach ($settings ['providers'] AS $settings_provider_key => $settings_provider_name)
115
+ {
116
+ if (isset ($oa_social_login_providers [$settings_provider_key]))
117
+ {
118
+ $providers [] = $settings_provider_key;
119
+ }
120
+ }
121
+ }
122
+
123
+ //Widget
124
+ if ($target == 'widget')
125
+ {
126
+ $css_theme_uri = 'http://oneallcdn.com/css/api/socialize/themes/wp_widget.css';
127
+ $show_title = false;
128
+ }
129
+ //Inline
130
+ else
131
+ {
132
+ $css_theme_uri = 'http://oneallcdn.com/css/api/socialize/themes/wp_inline.css';
133
+ $show_title = (empty($plugin_caption ) ? false : true);
134
+ }
135
+
136
+ //Build Redirection URL
137
+ if (in_the_loop())
138
+ {
139
+ $redirect_url = "'".get_permalink()."'";
140
+ }
141
+ else
142
+ {
143
+ $redirect_url = "window.location.href";
144
+ }
145
+
146
+ if (count ($providers) > 0)
147
+ {
148
+ ?>
149
+ <div class="oneall_social_login">
150
+ <?php
151
+ if ($show_title)
152
+ {
153
+ ?>
154
+ <div style="margin-bottom: 3px;"><label><?php _e ($plugin_caption, 'oa_social_login'); ?></label></div>
155
+ <?php
156
+ }
157
+ ?>
158
+ <div class="oneall_social_login_providers"></div>
159
+ <script type="text/javascript">
160
+ oneall.api.plugins.social_login.build("oneall_social_login_providers", {
161
+ 'providers' : ['<?php echo implode ("','", $providers); ?>'],
162
+ 'callback_uri': <?php echo $redirect_url; ?>,
163
+ 'css_theme_uri' : '<?php echo $css_theme_uri; ?>'
164
+ });
165
+ </script>
166
+ </div>
167
+ <?php
168
+ }
169
+ }
170
+ }
includes/widget.php ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Social Login Widget
5
+ */
6
+ class oa_social_login_widget extends WP_Widget
7
+ {
8
+ /**
9
+ * Constructor
10
+ */
11
+ public function __construct ()
12
+ {
13
+ parent::WP_Widget ('oa_social_login', 'Social Login', array (
14
+ 'description' => __ ('Allow your visitors to login and register with social networks like Twitter, Facebook, LinkedIn, Hyves, Google and Yahoo.', 'oa_social_login')
15
+ ));
16
+ }
17
+
18
+ /**
19
+ * Display the widget
20
+ */
21
+ public function widget ($args, $instance)
22
+ {
23
+ //Hide the widget for logged in users?
24
+ if (empty ($instance ['widget_hide_for_logged_in_users']) OR ! is_user_logged_in ())
25
+ {
26
+ //Before Widget
27
+ echo $args ['before_widget'];
28
+
29
+ //Title
30
+ if ( !empty ($instance ['widget_title']))
31
+ {
32
+ echo $args ['before_title'] . apply_filters ('widget_title', $instance ['widget_title']) . $args ['after_title'];
33
+ }
34
+
35
+ //Before Content
36
+ if ( !empty ($instance ['widget_content_before']))
37
+ {
38
+ echo $instance ['widget_content_before'];
39
+ }
40
+
41
+ //Content
42
+ oa_social_login_render_login_form (array (
43
+ 'target' => 'widget'
44
+ ));
45
+
46
+ //After Content
47
+ if ( !empty ($instance ['widget_content_after']))
48
+ {
49
+ echo $instance ['widget_content_after'];
50
+ }
51
+
52
+ //After Widget
53
+ echo $args ['after_widget'];
54
+ }
55
+ }
56
+
57
+ /**
58
+ * Show Widget Settings
59
+ */
60
+ public function form ($instance)
61
+ {
62
+ //Default settings
63
+ $default_settings = array (
64
+ 'widget_title' => __('Connect with').':',
65
+ 'widget_content_before' => '',
66
+ 'widget_content_after' => '',
67
+ 'widget_hide_for_logged_in_users' => '1'
68
+ );
69
+
70
+ foreach ($instance as $key => $value)
71
+ {
72
+ $instance [$key] = esc_attr ($value);
73
+ }
74
+
75
+ $instance = wp_parse_args ((array) $instance, $default_settings);
76
+ ?>
77
+ <p>
78
+ <label for="<?php echo $this->get_field_id ('widget_title'); ?>"><?php _e ('Title:', 'oa_social_login'); ?></label>
79
+ <input class="widefat" id="<?php echo $this->get_field_id ('widget_title'); ?>" name="<?php echo $this->get_field_name ('widget_title'); ?>" type="text" value="<?php echo $instance ['widget_title']; ?>" />
80
+ </p>
81
+ <p>
82
+ <label for="<?php echo $this->get_field_id ('widget_content_before'); ?>"><?php _e ('Insert content to add before the widget:', 'oa_social_login'); ?></label>
83
+ <textarea class="widefat" id="<?php echo $this->get_field_id ('widget_content_before'); ?>" name="<?php echo $this->get_field_name ('widget_content_before'); ?>"><?php echo $instance ['widget_content_before']; ?></textarea>
84
+ </p>
85
+ <p>
86
+ <label for="<?php echo $this->get_field_id ('widget_content_after'); ?>"><?php _e ('Insert content to add after the widget:', 'oa_social_login'); ?></label>
87
+ <textarea class="widefat" id="<?php echo $this->get_field_id ('widget_content_after'); ?>" name="<?php echo $this->get_field_name ('widget_content_after'); ?>"><?php echo $instance ['widget_content_after']; ?></textarea>
88
+ </p>
89
+ <p>
90
+ <input type="checkbox" id="<?php echo $this->get_field_id ('widget_hide_for_logged_in_users'); ?>" name="<?php echo $this->get_field_name ('widget_hide_for_logged_in_users'); ?>" type="text" value="1" <?php echo ( ! empty ($instance ['widget_hide_for_logged_in_users']) ? 'checked="checked"' : ''); ?> />
91
+ <label for="<?php echo $this->get_field_id ('widget_hide_for_logged_in_users'); ?>"><?php _e ('Tick to hide widget for logged in users', 'oa_social_login'); ?></label>
92
+ </p>
93
+ <?php
94
+ }
95
+
96
+
97
+ /**
98
+ * Update Widget Settings
99
+ */
100
+ public function update ($new_instance, $old_instance)
101
+ {
102
+ $instance = $old_instance;
103
+ $instance ['widget_title'] = trim(strip_tags ($new_instance ['widget_title']));
104
+ $instance ['widget_content_before'] = trim($new_instance ['widget_content_before']);
105
+ $instance ['widget_content_after'] = trim($new_instance ['widget_content_after']);
106
+ $instance ['widget_hide_for_logged_in_users'] = (empty($new_instance ['widget_hide_for_logged_in_users']) ? 0 : 1);
107
+ return $instance;
108
+ }
109
+ }
110
+
111
+ add_action ('widgets_init', create_function ('', 'return register_widget( "oa_social_login_widget" );'));
oa-social-login.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Social Login
4
+ Plugin URI: http://www.oneall.com/
5
+ Description: Allow your visitors to <strong>comment, login and register with 20+ social networks</strong> like Twitter, Facebook, LinkedIn, Hyves, Вконтакте, Google or Yahoo.
6
+ Version: 1.3.1
7
+ Author: Claude Schlesser
8
+ Author URI: http://www.oneall.com/
9
+ License: GPL2
10
+ */
11
+
12
+ define ('OA_SOCIAL_LOGIN_PLUGIN_URL', plugins_url () . '/' . basename (dirname (__FILE__)));
13
+
14
+ /**
15
+ * Check technical requirements before activating the plugin.
16
+ * Wordpress 3.0 or newer required
17
+ * CURL Required
18
+ */
19
+ function oa_social_login_activate ()
20
+ {
21
+ //Wordpress 3.0 or newer required
22
+ if (!function_exists ('register_post_status'))
23
+ {
24
+ deactivate_plugins (basename (dirname (__FILE__)) . '/' . basename (__FILE__));
25
+ echo sprintf (__ ("This plugin requires WordPress 3.0 or newer. Please update your WordPress installation to activate this plugin."));
26
+ exit;
27
+ }
28
+ elseif (!function_exists ('curl_version'))
29
+ {
30
+ deactivate_plugins (basename (dirname (__FILE__)) . '/' . basename (__FILE__));
31
+ echo sprintf (__ ("This plugin requires the <a href='http://www.php.net/manual/en/intro.curl.php'>PHP libcurl extension</a> be installed. Please contact your web host and request libcurl be <a href='http://www.php.net/manual/en/intro.curl.php'>installed</a>."));
32
+ exit;
33
+ }
34
+ update_option('oa_social_login_activation_message', 0);
35
+ }
36
+ register_activation_hook (__FILE__, 'oa_social_login_activate');
37
+
38
+ /**
39
+ * This file only need to be included for versions before 3.1.
40
+ * Deprecated since version 3.1, the functions are included by default
41
+ */
42
+ if (!function_exists ('email_exists'))
43
+ {
44
+ require_once(ABSPATH . WPINC . '/registration.php');
45
+ }
46
+
47
+
48
+
49
+ /**
50
+ * Include required files
51
+ **/
52
+ require_once(dirname (__FILE__) . '/includes/settings.php');
53
+ require_once(dirname (__FILE__) . '/includes/toolbox.php');
54
+ require_once(dirname (__FILE__) . '/includes/admin.php');
55
+ require_once(dirname (__FILE__) . '/includes/user_interface.php');
56
+ require_once(dirname (__FILE__) . '/includes/widget.php');
57
+
58
+ //Callback Handler
59
+ if (isset ($_POST) AND !empty ($_POST ['oa_action']) AND $_POST ['oa_action'] == 'social_login' AND !empty ($_POST ['connection_token']))
60
+ {
61
+ add_action ('init', 'oa_social_login_callback', 2000);
62
+ }
readme.txt ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Social Login ===
2
+ Contributors: ClaudeSchlesser
3
+ Tags: facebook, linkedin, google, yahoo, twitter, openid, wordpress.com, vkontakte, hyves, social connect, social login
4
+ Requires at least: 3.0
5
+ Tested up to: 3.2.1
6
+ Stable tag: 1.0
7
+
8
+ Allow your visitors to comment and login with social networks like Twitter, Facebook, LinkedIn, Hyves, OpenID, Вконтакте, Google, Yahoo
9
+
10
+ == Description ==
11
+
12
+ The Social Login Plugin is a professional though free plugin that allows your<br />
13
+ visitors to comment, login and register with social networks like Twitter, Facebook,<br />
14
+ LinkedIn, Hyves, Вконтакте, Google or Yahoo. <br /><br />
15
+
16
+ <strong>Choose where to add the social login feature:</strong><br />
17
+ <ul>
18
+ <li>On the comment formular</li>
19
+ <li>On the login page</li>
20
+ <li>On the registration page</li>
21
+ </ul>
22
+
23
+ <strong>Optionally add the widget:</strong><br />
24
+ <ul>
25
+ <li>A login widget that you can easily attach to your sidebar is provided</li>
26
+ </ul>
27
+
28
+ <strong>Select the Social Networks/Providers:</strong>
29
+ <ul>
30
+ <li>Facebook</li>
31
+ <li>Twitter</li>
32
+ <li>Google</li>
33
+ <li>LinkedIn</li>
34
+ <li>Yahoo</li>
35
+ <li>OpenID</li>
36
+ <li>Wordpress.com</li>
37
+ <li>Hyves</li>
38
+ <li>VKontakte (Вконтакте)</li>
39
+ </ul>
40
+ <br />
41
+
42
+ <strong>Draw a larger audience and increase user engagement in a few simple steps.</strong><br /><br />
43
+
44
+ The plugin is maintained by <a href="http://www.oneall.com">OneAll</a>, a technology company offering a set of web-delivered<br />
45
+ tools and services for establishing and optimizing a site's connection with many social providers<br />
46
+ such as Facebook, Twitter, Yahoo! and LinkedIn.
47
+
48
+
49
+ == Installation ==
50
+
51
+ 1. Upload the plugin folder to the "/wp-content/plugins/" directory of your WordPress site,
52
+ 2. Activate the plugin through the 'Plugins' menu in WordPress,
53
+ 3. Visit the "Settings\Social Login" administration page to setup the plugin.
54
+
55
+ == Frequently Asked Questions ==
56
+
57
+ = Do I have to add template tags to my theme? =
58
+
59
+ You should not have to change your templates.
60
+ The Social Login seamlessly integrates into your blog by using predefined hooks.
61
+
62
+ If you encounter nevertheless any problems, you can add the social login or registration forms to another location in
63
+ your theme by inserting the following code in that location:
64
+
65
+ `<?php do_action( 'oa_social_login' ); ?>`
66
+
67
+ = Do I have to change my Rewrite Settings? =
68
+
69
+ The plugins does not rely on mod_rewrite and does not need any additional rules.
70
+
71
+ = Where can I report bugs & get support? =
72
+
73
+ Our team answers your request at:
74
+ http://www.oneall.com/company/contact-us/
75
+
76
+ == Screenshots ==
77
+
78
+ 1. **Comment** - Comment formular (Social Network Buttons are includes)
79
+ 2. **Login** - Login formular (Social Network Buttons are includes)
80
+ 3. **Plugin Settings** - Plugin Settings in the Wordpress Administration Area
81
+ 4. **Widget Settings** - Widget Settings in the Wordpress Administration Area
82
+
83
+ == Changelog ==
84
+
85
+ = 1.0 =
86
+ * Initial release.
screenshot-1.png ADDED
Binary file
screenshot-2.png ADDED
Binary file
screenshot-3.png ADDED
Binary file
screenshot-4.png ADDED
Binary file